1、找出ifconfig “網卡名” 命令結果中本機的IPv4地址
ifconfig | head -n 2 |tail -1 |tr -s " " |cut -d" " -f3
2、查出分區空間使用率的最大百分比值
df |tr -s " " |cut -d" " -f5
3、查出用戶UID最大值的用戶名、UID及shell類型
cat /etc/passwd | cut -d: -f1,3,7| sort -nt: -k2 |tail -n 1
4、查出/tmp的權限,以數字方式顯示
stat /tmp | head -n 4 |tail -n 1|cut -c10-13
5、統計當前連接本機的每個遠程主機IP的連接數,並按從大到小排序(無圖)
cat /var/log/httpd/access_log |cut -d" " -f1 |sort |uniq -c |sort -n -r |head
6、顯示CentOS7的/etc/grub2.cfg文件中,至少以一個空白字符開頭的且後面存非空白字符的行
grep "^[[:blank:]]+" /etc/grub2.cfg |grep -v "^[[:space:]]$"
7、找出“netstat -tan”命令的結果中以‘LISTEN’後跟任意多個空白字符結尾的行
netstat -tan |grep "LISTEN[[:blank:]]$"
8、顯示CentOS7上所有系統用戶的用戶名和UID
cat /etc/passwd |cut -d: -f1,3 | egrep -v "[0-9]{4,}"
9、添加用戶bash、testbash、basher、sh、nologin(其shell爲/sbin/nologin),找出/etc/passwd用戶名同shell名的行
grep "(^.)\>.\<\1$" /etc/passwd
10、利用df和grep,取出磁盤各分區利用率,並從大到小排序
df |egrep "\<[0-9]%." -o|sort -nr
11、顯示三個用戶root、mage、wang的UID和默認shell(C7代替)
cat /etc/passwd |egrep "^(root|C7)" |cut -d: -f1,3
12、找出/etc/rc.d/init.d/functions文件中行首爲某單詞(包括下劃線)後面跟一個小括號的行
egrep ".()" /etc/rc.d/init.d/functions
13、使用egrep取出/etc/rc.d/init.d/functions中其基名(弄得有點投機嫌疑)
echo /etc/rc.d/init.d/functions | egrep "[a-z]$"
14、使用egrep取出上面路徑的目錄名
echo /etc/rc.d/init.d/functions | egrep "/.*/"
15、統計last命令中以root登錄的每個主機IP地址登錄次數
last|cut -c23-38 |sort|uniq -c|sort -rn|head -n 1
16、利用擴展正則表達式分別表示0-9、10-99、100-199、200-249、250-255
echo {1..255} |
egrep "\<[0-9]\>"
egrep "\<1[0-9]\>"
egrep "\<1[0-9][0-9]\>"
egrep "\<2[0-4][0-9]\>"
egrep "\<25[0-5]\>"
17、顯示ifconfig命令結果中所有IPv4地址(瞎寫)
ifconfig |egrep "[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}"
18、將此字符串:welcome to tiantianpaokuzhentmdehaowan linux 中的每個字符去重並排序,重複次數多的排到前面
echo wecomele to tiantianpaokuzhentmdehaowan linux |grep -o . |sort |uniq -c |sort -nr
如有錯誤之處還請批評指正。
Linux中正則表達式的練習集合
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
grep、正則表達式和擴展正則表達式的理解及運用
shang61511
2019-02-23 14:04:46
正則表達式及grep過濾工具的簡單介紹
596433405
2019-02-23 13:17:49
[轉帖]看看一位清華計算機專業的學生怎麼看LINUX與WINDOWS
jackieban
2019-02-23 13:57:24
SE LINUX下磁盤IO性能監測分析
xuts5
2019-02-23 13:48:29
LINUX擴展
ruzhulinux
2019-02-23 13:35:11
DELL服務器裝LINUX系統只能識別2T大小解決方法
pengjian06
2019-02-23 13:20:49
爲suse 12.3桌面系統安裝金山WPS OFFICE
emlony20000
2019-02-23 13:16:33
基於 NFA 實現正則表達式引擎
時間被海綿吃了
2019-02-23 14:04:35
ASP.NET正則表達式提取網頁資源
jackywei1987
2019-02-23 13:51:42
python的正則表達式模塊re
窈窕魑魅
2019-02-23 13:14:46
sed及grep用法詳解
cc532321437
2019-02-23 13:37:43
Linux Linux grep命令用法以及正則表達
qq_tang
2019-02-23 13:27:08