重定向和管道流練習
1.將/etc/issue文件中的內容轉換爲大寫後保存至/tmp/issue.out文件中
答:cat /etc/issue | tr 'a-z' 'A-Z' > /tmp/issye.out正則表達式
2.將當前系統登陸用戶的信息轉換爲大寫後保存至/tmp/who.out文件中
答:who | tr 'a-z' 'A-Z' > /tmp/who.outshell
3.一個Linux用戶給root發郵件,要求郵件標題爲「help」 ,郵件正文以下:hello,i am 用戶名,The system version is here ,please help me to check it ,thanks . 操做系統版本信息.
答:mail -s help root <<EOFcentos
hello,i am
hostname
The system version is here ,please help me to check it ,thanksecho /etc/centos-release
EOFbash
4.將/root/下文件列表,顯示成一行,並文件名之間用空格隔開
答:ls /root | tr "\n" " "ide
5.計算1+2+3+...+99+100的總和
答:echo {1 2 3...100} | tr " " + | bcspa
6.刪除Windows文本文件中的回車字符,即「/r」
答:car /txt1 | tr -d "/r"操作系統
正則表達式練習
1.顯示/proc/meminfo文件中以大小s開頭的行(要求使用兩種方法)
答:1:cat /proc/meminfo | grep "^[s,S]" 2:cat /proc/meminfo | grep -i "^s"code
2.顯示/etc/passwd文件中不以/bin/bash結尾的行
答:cat /etc/passwd|grep -v "/bin/bash$"排序
3.顯示用戶rpc 默認的shell程序
答:cat /etc/passwd|grep -w rpc|cut -d: -f7rpc
4.找出/etc/passwd中的兩位或三位數
答:1:cat /etc/passwd|grep -w -e [0-9][0-9][0-9] -e [0-9][0-9]
2:cat /etc/passwd|grep -E -w -e [0-9]{2,3}
5.顯示CentOS7的/etc/grub2.cfg文件中,至少以一個空白字符開頭的且後面有非空白字符的行
答:cat /etc/grub2.cfg |grep -E ^[[:space:]]+
6.找出「netstat-tan」命令結果中以LISTEN後跟任意多個空白字符結尾的行
答:netstat -tan|grep -e LISTEN[[:space:]]*$
7.顯示CentOS上全部系統用戶的用戶名和UID
答:cat /etc/passwd | cut -d: -f1,3
8.添加用戶bash、testbash、basher、sh、nologin(其shell爲/sbin/nologin),找出/etc/passwd用戶名和shell同名的行
答:grep -E "(^[[:alpha:]]+):.*\1$" /etc/passwd
9.利用df和grep,取出磁盤各分區利用率,並從大到小排序答:df|grep -e /dev/sd|tr -s " " %|cut -d% -f5|sort -nr