1 、取本機ip地址
Centos6.8
ifconfig | head -2|tail -1|cut -d: -f2|cut -d" " -f1
ifconfig | head -2|tail -1|cut -d: -f2|cut -dB -f1
Centos7.2
ifconfig|head -2|tail -1|cut -dt -f2|cut -d" " -f2
2 、查出分區空間使用率的最大百分比值
df|tr -s " "|cut -d" " -f5|tr -d '%'|tail -n +2
3 、查出用戶UID 最大值的用戶名、UID 及shell 類型
getent passwd|sort -n -t: -k3|cut -d: -f1,3,7|tail -1
4 、查出/tmp 的權限,以數字方式顯示
stat /tmp|head -n 4|tail -n +4|cut -d\( -f2|cut -d\/ -f1
5 、統計當前連接本機的每個遠程主機IP 的連接數,并按從大到小排序
netstat -nt|tr -s " "|cut -d" " -f5|cut -d: -f1|tail -n +3|sort|uniq -c|sort -n -r
6 、顯示/proc/meminfo 文件中以大小s 開頭的行;( 要求:使用兩種方式)
grep "^[Ss]" /proc/meminfo
egrep "^(S|s)" /proc/meminfo
grep -i "^s" /proc/memsinfo
7、顯示/etc/passwd 文件中不以/bin/bash 結尾的行
grep -v /bin/bash$ /etc/passwd
8、顯示用戶rpc 默認的shell 程序
grep "^rpc\>" /etc/passwd|cut -d: -f7
9 、找出/etc/passwd 中的兩位或三位數
egrep -o "([[:digit:]]{2,3})" /etc/passwd
10、顯示/etc/grub2.cfg 文件中,至少以一個空白字符開頭的且后面存非空白字符的行
egrep "^[[:space:]]+[^[:space:]]" /etc/grub2.cfg
11、找出“netstat -tan” 命令 的結果 中以‘LISTEN’ 后跟任意多個空白字符結尾的行
netstat -tan|egrep "(LISTEN)[[:space:]]*$"
12 、添加用戶bash 、testbash 、basher 以及nologin( 其shell為 為/sbin/nologin), 而后找出/etc/passwd 文件中用戶名同shell名的行
egrep "^([[:alnum:]]*):.*\1$" /etc/passwd
13、統計/etc/init.d/functions 文件中每個單詞出現的次數,并按頻率從高到低顯示
cat /etc/init.d/functions |egrep -o "([[:alpha:]]*)" |sort|uniq -c|sort -n -r
14、/etc/rc.d/init.d/functions或/etc/rc.d/init.d/functions/" 取目錄名或基名
echo "/testdir/dir/dir1/" | egrep -o ".*/\<" #目錄名
echo "/testdir/dir/dir1/" | egrep -o "([^/]+\/?)$" #基名
15、正則表達式表示身份證號
egrep "\<((1[1-5])|(2[1-3])|(3[1-7])|(4[1-6])|(5[0-4])|(6[1-5])|(71|81|82))([0-9]){4}(19|20)([0-9]){2}((0[1-9])|(1[0-2]))(0[1-9]|(1[0-9])|(2[0-9])|(3[0-1]))([0-9]){3}([0-9]|X)\>" filename
16、正則表達式表示手機號
grep -E -o "(\+86)?1[38][0-9]{9}|14[57][0-9]{8}|15[0-35-9][0-9]{8}|17[0678][0-9]{8}" shoujihao
17、正則表達式表示郵箱
egrep "\<([[:alnum:]]+(-|_)*[[:alnum:]]*)\>@([[:alnum:]]+\.)+[[:alnum:]]+" mail grep -E -o '[a-zA-Z0-9]+[[:alnum:]\.\_-]*@[a-zA-Z0-9]+[[:alnum:]\.\_-]*' mail
18、正則表達式表示QQ號
grep -E -o '\b[1-9][0-9]{4,12}\b' QQ
原創文章,作者:NameLess,如若轉載,請注明出處:http://www.www58058.com/32396