8.1-用戶和組(作業篇)

 1、將/etc/issue文件中的內容轉換為大寫后保存至/tmp/issue.out文件中。

[root@localhost ~]# tr a-z A-Z </etc/issue > /tmp/issue.out
[root@localhost ~]# cat /tmp/issue.out 
CENTOS RELEASE 6.8 (FINAL)
KERNEL \R ON AN \M

2、將當前系統登錄用戶的信息轉換為大寫后保存至/tmp/who.out文件中。

[root@localhost ~]# who | tr a-z A-Z > /tmp/who.out
[root@localhost ~]# cat /tmp/who.out 
ROOT     TTY1         2016-07-21 03:43
ROOT     PTS/0        2016-07-21 03:45 (10.1.252.7)

3、一個linux用戶給root發郵件,要求郵件標題為”help”,郵件正文如下:Hello, I am 用戶名,the system version is here,pleasehelp

 me to check it ,thanks!操作系統版本信息。

普通用戶:
[cej@localhost ~]$ echo "Hello,i am `whoami`,the system version is here,pleasehelp me to check it ,thanks! `uname -r`"| mail -s Hello root
root:
[root@localhost ~]# mail
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N  1 cej@localhost.locald  Thu Jul 21 03:53  18/687   "Hello"
& 1
Message  1:
From cej@localhost.localdomain  Thu Jul 21 03:53:17 2016
Return-Path: <cej@localhost.localdomain>
X-Original-To: root
Delivered-To: root@localhost.localdomain
Date: Thu, 21 Jul 2016 03:53:17 +0800
To: root@localhost.localdomain
Subject: Hello
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: cej@localhost.localdomain
Status: R
Hello,i am cej,the system version is here,pleasehelp me to check it ,thanks! 2.6.32-642.el6.x86_64

4、將/root/下文件列表,顯示成一行,并文件名之間用空格隔開。

[root@localhost ~]# ls /root/
anaconda-ks.cfg  install.log  install.log.syslog  公共的  模板  視頻  圖片  文檔  下載  音樂  桌面

ls雖然輸出至屏幕顯示在一行,觀察輸出至文件得知實際上是分行顯示

[root@localhost ~]# ls /root/ > /tmp/root.txt
[root@localhost ~]# cat /tmp/root.txt 
anaconda-ks.cfg
install.log
install.log.syslog
公共的
模板
視頻
圖片
文檔
下載
音樂
桌面

[root@localhost ~]# ls /root/|tr ["\n"] ["\040"]
anaconda-ks.cfg install.log install.log.syslog 公共的 模板 視頻 圖片 文檔 下載 音樂 桌面 [root@localhost ~]#

5、file1文件的內容為:”1 2 3 4 5 6 7 8 9 10” 計算出所有數字的總和。

[root@localhost ~]# cat file1 
1 2 3 4 5 6 7 8 9 10
[root@localhost ~]# tr ' ' '+' <file1 
1+2+3+4+5+6+7+8+9+10
[root@localhost ~]# tr ' ' '+' <file1 |bc
55

6、刪除Windows文本文件中的'^M'字符


[root@localhost ~]# cat -A windows.txt 
a^M$
a^M$
a^M$
a^M$
a^M$
[root@localhost ~]# tr -d '\015' <file1 
1 2 3 4 5 6 7 8 9 10
[root@localhost ~]# tr -d '^M' <file1 
1 2 3 4 5 6 7 8 9 10

 

7、處理字符串“xt.,l 1 jr#!$mn2 c*/fe3 uz4”,只保留其中的數字和空格。

[root@localhost ~]# echo 'xt.,l 1 jr#!$mn2 c*/fe3 uz4' | tr -cd '[0-9][ ]'
 1 2 3 4

 

8、將PATH變量每個目錄顯示在獨立的一行。

[root@localhost ~]# echo $PATH | tr ':' '\n'
/usr/lib64/qt-3.3/bin
/usr/local/sbin
/usr/local/bin
/sbin
/bin
/usr/sbin
/usr/bin
/root/bin

9、刪除指定文件的空行。

[root@localhost ~]# cat line.txt 
aaaaaaaaaaaa

bbbbbbbbbbbb

vvvvvvvvvvvv
[root@localhost ~]# cat line.txt| tr -s '\n'  
aaaaaaaaaaaa
bbbbbbbbbbbb
vvvvvvvvvvvv

10、將文件中每個單詞(字母)顯示在獨立的一行,并無空行。

[root@localhost ~]# cat /etc/issue | tr -s ' ' '\n'
CentOS
release
6.8
(Final)
Kernel
\r
on
an
\m

11、創建用戶gentoo,附加組為bin和root,默認shell為/bin/csh,注釋信息為"Gentoo Distribution"

[root@localhost ~]# groups bin
bin : bin daemon sys
[root@localhost ~]# groups root
root : root
[root@localhost ~]# useradd -s /bin/csh -c "Gentoo Distribution" -G bin,root gentoo
[root@localhost ~]# tail -1 /etc/passwd
gentoo:x:501:501:Gentoo Distribution:/home/gentoo:/bin/csh
[root@localhost ~]# grep -E "(^bin|^root)" /etc/group
root:x:0:gentoo
bin:x:1:bin,daemon,gentoo

2、創建下面的用戶、組和組成員關系
(1)名字為admins 的組
(2)用戶natasha,使用admins 作為附屬組
(3)用戶harry,也使用admins 作為附屬組
(4)用戶sarah,不可交互登錄系統, 且不是admins 的成員,natasha, harry, sarah密碼都是centos

[root@localhost ~]# groupadd admins
[root@localhost ~]# tail -1 /etc/group
admins:x:502:
[root@localhost ~]# useradd -G admins natasha
[root@localhost ~]# useradd -G admins harry
[root@localhost ~]# tail -3 /etc/group
admins:x:502:natasha,harry
natasha:x:503:
harry:x:504:
[root@localhost ~]# useradd -s /sbin/nologin sarah
[root@localhost ~]# echo "centos" | passwd --stdin natasha
更改用戶 natasha 的密碼 。
passwd: 所有的身份驗證令牌已經成功更新。
[root@localhost ~]# echo "centos" | passwd --stdin harry
更改用戶 harry 的密碼 。
passwd: 所有的身份驗證令牌已經成功更新。
[root@localhost ~]# echo "centos" | passwd --stdin sarah
更改用戶 sarah 的密碼 。
passwd: 所有的身份驗證令牌已經成功更新。

 


1、創建testuser uid 1234,主組:bin,輔助組:root,ftp,shell:/bin/csh home:/testdir/testuser

[root@localhost ~]# mkdir /testdir
[root@localhost ~]# useradd testuser -u 1234 -g bin -G root,ftp -s /bin/csh -d /testdir/testuser

2、修改testuser uid:4321,主組:root,輔助組:nobody,loginname:test,home:/home/test 家數據遷移

[root@localhost ~]# usermod -u 4321 -g root -G nobody -l test -md /home/test testuser 
[root@localhost ~]# id test
uid=4321(test) gid=0(root) 組=0(root),99(nobody)
[root@localhost ~]# getent passwd test
test:x:4321:0::/home/test:/bin/csh

3、批量創建帳號:user1…user10
(1)、uid:3000-3009,shell:/bin/csh,home:/testdir/username
(2)、passwd:usernamepass
(3)、注意家目錄相關配置,使用戶正常登錄

[root@localhost ~]# cat user.txt 
user1:!!:3000:3000::/testdir/user1:/bin/csh
user2:!!:3001:3001::/testdir/user2:/bin/csh
user3:!!:3002:3002::/testdir/user3:/bin/csh
user4:!!:3003:3003::/testdir/user4:/bin/csh
user5:!!:3004:3004::/testdir/user5:/bin/csh
user6:!!:3005:3005::/testdir/user6:/bin/csh
user7:!!:3006:3006::/testdir/user7:/bin/csh
user8:!!:3007:3007::/testdir/user8:/bin/csh
user9:!!:3008:3008::/testdir/user9:/bin/csh
user10:!!:3009:3009::/testdir/use10:/bin/csh
[root@localhost ~]# cat passwd.txt 
user1:user1pass
user2:user2pass
user3:user3pass
user4:user4pass
user5:user5pass
user6:user6pass
user7:user7pass
user8:user8pass
user9:user9pass
user10:user10pass
[root@localhost ~]# newuser user.txt
[root@localhost ~]# cat passwd.txt | chpasswd

[root@localhost ~]# tail -10 /etc/passwd
user1:x:3000:3000::/testdir/user1:/bin/csh
user2:x:3001:3001::/testdir/user2:/bin/csh
user3:x:3002:3002::/testdir/user3:/bin/csh
user4:x:3003:3003::/testdir/user4:/bin/csh
user5:x:3004:3004::/testdir/user5:/bin/csh
user6:x:3005:3005::/testdir/user6:/bin/csh
user7:x:3006:3006::/testdir/user7:/bin/csh
user8:x:3007:3007::/testdir/user8:/bin/csh
user9:x:3008:3008::/testdir/user9:/bin/csh
user10:x:3009:3009::/testdir/use10:/bin/csh
[root@localhost ~]# tail -10 /etc/shadow
user1:$6$9fYDi/ka1/Z/$NrWYcHvh4zvoaemMPU1GwNBNwe94LoS.bTJzcTYZkMK6LAjUBp4PkY9WnKn8/0MPtXEdnMgHwCYe.u0g/7Qpy/:17002:0:99999:7:::
user2:$6$S5.GJ/nwdsxNj2A9$J0Eb1QwtgoxzuxkRf4Pr/e2lF/.E6T111O1s9.VpLfS78HZMKocuoS3F2Vw3v0ilmPJZFwyIzhCK8O7ZzQLk2/:17002:0:99999:7:::
user3:$6$sZs15/qhGLD$3I0n8vPYACVYEuDcypd/veuTXGsay7U6DYKq6ucKHcB.LEG0M3z5G1umy3GwlCth9RQWACmrOr/bcfrIRalUj1:17002:0:99999:7:::
user4:$6$rBLHbzMoIA/d$Scv/W4M1rh4L7os43BQygRVaNeLgAQLZ5rcmShOiSzFiAAu3Poe6HpXLpHf7WcxD5OjY6Ae.b0EsDI6RI3z9c1:17002:0:99999:7:::
user5:$6$r6wYO/ny1E31$mhpih1Wy56xk1OR6lXFTOn1sOUhazoTy5va7LXmKDRnFxe8cO5be.VLVWXcO6sDFZWl1i4DydIRzVLvirB0A01:17002:0:99999:7:::
user6:$6$Xbdfi/6pUJI/tX$EzjSufBp6L669jc.fFMMmGIf6SZg5IHFQWbBtRBd8gcMgwiAn6mQAYuM2gbwHnVBwpozLYsLESMAmB8tOL58U1:17002:0:99999:7:::
user7:$6$A38dq/2fvTr/$NfCir91Igb03gseViQm0UTY4CNZdnfkLgPcit2Q9Ey643wmzNc1V3hSBJa0eTGZCRWCpQOQ.1H8zVlsW0Er5I/:17002:0:99999:7:::
user8:$6$IyWsW/bB1$bpcadfLAT8zybea0o.JTnHo4D3XlaYCQP2uaoKzIPW0dDqBXIh86ewksdZHM4EADqPjcQg.yOyk3ktziBIJYc0:17002:0:99999:7:::
user9:$6$N1jQs/D42PH$l/aR0nCJX3i4s5zoKMgLN1U.HTqIlR/YbFwY5YqTVFZBrlTKiFDE9Z9QvQ3cei3psu.jaX026.pFOgfXOxDM01:17002:0:99999:7:::
user10:$6$YiHga/zg5Qs/zOjS$9uKAP3FMlx/ZwUYyQJHXBrGuor/CaMfk4SUTQkXn1Af08Ler7p6nv55rMSX.oDsJ2FWFCEz/WsOiwYd/oCmn0/:17002:0:99999:7:::

[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use1
[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use2
[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use3
[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use4
[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use5
[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use6
[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use7
[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use8
[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use9
[root@localhost ~]# cp -r /etc/skel/.[^.]* /testdir/use10

[c:\~]$ ssh 
[c:\~]$ Connecting to 10.1.252.66:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
[user1@localhost ~]$ 
正常登陸!










原創文章,作者:M20-1--孔祥文,如若轉載,請注明出處:http://www.www58058.com/27179

(0)
M20-1--孔祥文M20-1--孔祥文
上一篇 2016-08-04
下一篇 2016-08-04

相關推薦

  • 詳解LVM邏輯卷

       LVM邏輯卷管理 當os6中partprobe 命令不能同步分區完的分區信息,及用ll /dev/sd*、cat /proc/partation、lsblk看的設備分區內容和用fdisk -l 看到的信息不同步 所以用partx -a 設備名或者用partx -a –nr 分區號 設備名 其中表示n是設備名,r 是ran…

    Linux干貨 2016-08-29
  • pam_mysql認證ftp虛擬用戶賬號

    pam_mysql認證ftp虛擬用戶賬號: 虛擬用戶:        用戶賬號存儲于何處?        文件、MySQL、Redis、…       &nb…

    2017-06-13
  • ArchSummit 2017全球架構師峰會100余位國內外技術專家北京等你!

    ArchSummit全球架構師峰會是InfoQ中國團隊推出的面向高端技術管理者、架構師的技術大會,參會者中超過50%擁有8年以上的工作經驗。

    2017-11-13
  • ?磁盤管理、MBR、GPT、分區工具、文件系統、常見分區掛載

    磁盤管理{磁盤結構;MBR;GPT;分區工具;文件系統;分區掛載;}

    Linux干貨 2016-08-29
  • N22第八周作業

    1、請描述網橋、集線器、二層交換機、三層交換機、路由器的功能、使用場景與區別。 網橋: 網橋是早期的二層網絡設備,每個端口分別有一條獨立的交換信道,不是共享一條信道,可隔離沖突域。網橋比集線器(Hub)性能更好,集線器上各端口都是共享同一條信道的,工作于數據鏈路層。后被端口更多的交換機替代。 集線器: 多端口中繼器,工作在物理層,本身不具備識別信號的能力,只…

    Linux干貨 2016-10-17
  • Linux nginx 服務

                           Linux nginx 服務 Nginx服務簡介:      NGINX :是一個自由、開源、高性能、輕量級的HT…

    系統運維 2016-11-18

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-08-04 15:17

    作業完成的很好,排版也很用心,再接再厲。

欧美性久久久久