1、將/etc/issue文件中的內容轉換爲大寫後保存至/tmp/issue.out文件中
[root@liang /]# cat /etc/issue | tr 'a-z' 'A-Z' > /tmp/issue.out [root@liang /]# cat /tmp/issue.out CENTOS RELEASE 6.8 (FINAL) KERNEL \R ON AN \M
2、將當前系統登錄用戶的信息轉換爲大寫後保存至/tmp/who.out文件中
[root@liang /]# who | tr 'a-z' 'A-Z' > /tmp/who.out [root@liang /]# cat /tmp/who.out ROOT PTS/0 2016-08-02 17:54 (192.168.99.1)
3、一個linux用戶給root發郵件,要求郵件標題爲”help”,郵件正文如下:
Hello, I am 用戶名,the system version is here,please help me to check it ,thanks!
操作系統版本信息
[liang@liang ~]$ echo -e "Hello,I am `whoami`,the system version is here,please help me to check it,thanks! \n`cat /etc/centos-release`" | mail -s help root
4、將/root/下文件列表,顯示成一行,並文件名之間用空格隔開
[root@liang /]# ls -a /root/ | tr '\n' ' ' . .. aa.log anaconda-ks.cfg .bash_history .bash_logout .bash_profile .bashrc .cshrc file1 install.log install.log.syslog .lesshst mail .tcshrc .viminfo .Xauthority
5、file1文件的內容爲:”1 2 3 4 5 6 7 8 9 10” 計算出所有數字的總和
[root@liang ~]# echo $[`cat file1 | tr -t ' ' '+'`] 55 [root@liang ~]# cat file1 | tr -t ' ' '+' | bc 55
6、處理字符串“xt.,l 1 jr#!$mn2 c*/fe3 uz4”,只保留其中的數字和空格
[root@liang ~]# echo "xt.,l 1 jr#bcmn2 c*/fe3 uz4" | tr -cd '[:digit:] ' 1 2 3 4
7、將PATH變量每個目錄顯示在獨立的一行
[root@liang ~]# echo $PATH | tr ':' '\n' /usr/lib64/qt-3.3/bin /usr/local/sbin /usr/local/bin /sbin /bin /usr/sbin /usr/bin /root/bin
8、刪除指定文件多餘的空行
[root@liang ~]# cat aa.log hello ,i am root , my os is CentOS release 6.8 (Final) [root@liang ~]# cat aa.log | tr -s '[:space:]' hello ,i am root , my os is CentOS release 6.8 (Final)
9、將文件中每個單詞(字母)顯示在獨立的一行,並無空行
[root@liang ~]# cat aa.log | tr -cs '[:alpha:]' '\n' hello i am root my os is CentOS release Final
10、創建testuser用戶,要求 uid 1234,主組:bin,輔助組:root,ftp,shell:/bin/csh home:/testdir/testuser
[root@liang testuser]# useradd -u 1234 -g bin -G root,ftp -s /bin/csh -d /testdir/testuser testuser [root@liang testuser]# id testuser uid=1234(testuser) gid=1(bin) 組=1(bin),0(root),50(ftp) [root@liang testuser]# getent passwd testuser testuser:x:1234:1::/testdir/testuser:/bin/csh
11、修改testuser用戶,要求 uid:4321,主組:root,輔組:nobody,登錄用戶名:test,家目錄:/home/test 且家數據遷移
[root@liang testuser]# usermod -u 4321 -g root -G nobody -l test -d /home/test -m testuser [root@liang test]# getent passwd test test:x:4321:0::/home/test:/bin/csh [root@liang test]# id test uid=4321(test) gid=0(root) 組=0(root),99(nobody)
12、批量創建帳號:user1...user10,要求uid:3000-3009,shell:/bin/csh,家目錄:/testdir/username
用戶密碼:usernamepass
(1)創建用戶批量文件
[root@liang /]# vim userlist [root@liang /]# cat userlist user1:x:3000:3000::/home/user1:/bin/csh user2:x:3001:3001::/home/user2:/bin/csh user3:x:3002:3002::/home/user3:/bin/csh user4:x:3003:3003::/home/user4:/bin/csh user5:x:3004:3004::/home/user5:/bin/csh user6:x:3005:3005::/home/user6:/bin/csh、 user7:x:3006:3006::/home/user7:/bin/csh user8:x:3007:3007::/home/user8:/bin/csh user9:x:3008:3008::/home/user9:/bin/csh user10:x:3009:3009::/home/user10:/bin/csh
(2)使用newusers命令調用用戶批量文件
[root@liang /]# newusers userlist [root@liang /]# getent passwd ... user1:x:3000:3000::/home/user1:/bin/csh user2:x:3001:3001::/home/user2:/bin/csh user3:x:3002:3002::/home/user3:/bin/csh user4:x:3003:3003::/home/user4:/bin/csh user5:x:3004:3004::/home/user5:/bin/csh user6:x:3005:3005::/home/user6:/bin/csh user7:x:3006:3006::/home/user7:/bin/csh user8:x:3007:3007::/home/user8:/bin/csh user9:x:3008:3008::/home/user9:/bin/csh user10:x:3009:3009::/home/user10:/bin/csh
(3)將用戶的家目錄複製過來,家目錄模板文件在/etc/skel目錄下
[root@liang etc]# cp -r /etc/skel/.[^.]* /home/user1 [root@liang etc]# cp -r /etc/skel/.[^.]* /home/user2 [root@liang etc]# cp -r /etc/skel/.[^.]* /home/user3 [root@liang etc]# cp -r /etc/skel/.[^.]* /home/user4 [root@liang etc]# cp -r /etc/skel/.[^.]* /home/user5 [root@liang etc]# cp -r /etc/skel/.[^.]* /home/user6 [root@liang etc]# cp -r /etc/skel/.[^.]* /home/user7 [root@liang etc]# cp -r /etc/skel/.[^.]* /home/user8 [root@liang etc]# cp -r /etc/skel/.[^.]* /home/user9 [root@liang etc]# cp -r /etc/skel/.[^.]* /home/user10 [root@liang user1]# ls -a /home/user1 . .. .bash_logout .bash_profile .bashrc .gnome2
(4)修改各個用戶家目錄所有者及權限
[root@liang home]# chown -R user1:user1 user1 [root@liang home]# chown -R user1:user1 user2 [root@liang home]# chown -R user1:user1 user3 [root@liang home]# chown -R user1:user1 user4 [root@liang home]# chown -R user1:user1 user5 [root@liang home]# chown -R user1:user1 user6 [root@liang home]# chown -R user1:user1 user7 [root@liang home]# chown -R user1:user1 user8 [root@liang home]# chown -R user1:user1 user9 [root@liang home]# chown -R user1:user1 user10
(5)創建用戶密碼列表
[root@liang /]# vim passwdlist [root@liang /]# cat passwdlist user1:user1 user2:user2 user3:user3 user4:user4 user5:user5 user6:user6 user7:user7 user8:user8 user9:user9 user10:user10
(6)使用chpasswd命令調用用戶米密碼列表
[root@liang /]# cat passwdlist | chpasswd #調用密碼文件批量設置用戶密碼 [root@liang /]# getent shadow user1 #查看user1的密碼 user1:$6$9C8gM/W7$ECVWuxrsOMNehJQn8UvM/2aBvlRExF3hizdxVdIIYFki.5Jl68GQh.O8.h3KgAwJMQ.lD3yti.I4l4PiEy7qr.:17020:0:99999:7:::