面授20期2班-08月4號課堂與課后習題

課堂習題

1、顯示/etc/init.d/functions文件中所有的單詞及出現的次數

cat /etc/init.d/functions | tr -sc "[:alpha:]" '\n' |sort | uniq -c

2、找出ifconfig命令結果中本機的所有IPv4地址

centos6:ifconfig | head -2 | tail -1 | cut -d: -f 2 | cut -d" " -f1

centos7:ifconfig | head -2 | tail -1 | cut -dt -f2 | cut -d" " -f2

3、查出分區空間使用率的最大百分比值

[root@shao ~]# df | cut -c 44-46 | sort -nr | head -n2 | tail -n1

4、查出用戶UID最大值的用戶名、UID及shell類型

方法一 cat /etc/passwd | cut -d: -f1,3,7 | sort -nrt : -k 2 |head -n 1

方法二 sort -nrt: -k3 /etc/passwd | head -n1 | cut -d: -f1,3,7

5、查出/tmp的權限,以數字方式顯示

 stat /tmp | head -4 | tail -1 | cut -d/ -f1 | cut -d\( -f2

6、統計當前連接本機的每個遠程主機IP的連接數,并按從大 到小排序

netstat -tn | cut -d: -f2 | tr -s " " ":" | cut -d: -f2 | sort | uniq -c

7、顯示/proc/meminfo文件中以大小s開頭的行;(要求:使 用兩種方式)

方法一 grep -e ^s -e ^S  /proc/meminfo
方法二 grep -i ^s  /proc/meminfo
方法三 grep  ^[sS]  /proc/meminfo

8、顯示/etc/passwd文件中不以/bin/bash結尾的行

grep -v "/bin/bash$" /etc/passwd

9、顯示用戶rpc默認的shell程序

getent passwd | grep ^"\<rpc\>" | cut -d: -f1,7

10、找出/etc/passwd中的兩位或三位數

grep -o "\<[[:digit:]]\{2,3\}\>" /etc/passwd

11、顯示/etc/grub2.cfg文件中,至少以一個空白字符開頭的 且后面存非空白字符的行

grep -o  "^[[:space:]]\+[^[:space:]].*" /etc/grub2.cf

12、找出"netstat -tan"命令的結果中以'LISTEN'后跟0、1 或多個空白字符結尾的行

netstat -tan | grep "\<LISTEN[[:space:]]*$"

13、添加用戶bash、testbash、basher以及nologin(其shell為 /sbin/nologin),而后找出/etc/passwd文件中用戶名同shell名的行

 useradd -s /sbin/nologin nologin
 useradd bash
 useradd testbash

方法一 getent passwd | grep "^\(\<.*\>\).*\<\1\>$"

方法二 getent passwd | grep "^\(\<[[:alnum:]]\{1,\}\>\).*\<\1\>$"

14、顯示當前系統root或mage用戶的UID和默認shell

方法一 grep -E "^(root|mage):" /etc/passwd | cut -d: -f3,7

方法二 grep -e "^root\<" -e "^mage\<" /etc/passwd | cut -d: -f3,7

15、找出/etc/rc.d/init.d/functions文件中行首為某單詞(包括下劃線)后面跟一個小括號的行

grep  -E  "^([[::alpha]_])+\(\).*" /etc/rc.d/init.d/functions

16、使用egrep取出/etc/rc.d/init.d/functions中其基名

echo /etc/rc.d/init.d/functions | egrep -o "f.*$"

17、使用egrep取出上面路徑的目錄名

echo /etc/rc.d/init.d/functions | egrep -o "^.*/"

18、統計以root身份登錄的每個遠程主機IP地址的登錄次數

last | grep root | egrep -o "[[:digit:]]+.[[:digit:]]+.[[:digit:]]+.[[:digit:]]+" | uniq -c | sort -t" "


課后練習

1、用擴展正則表達式表示IP地址

ifconfig | egrep -o "\<(((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\>"

2、用擴展正則表達式表示手機號13 14 17 15  18

egrep -o "\<1[134578][0-9]{9}\>"

3、用擴展正則表達式表示身份證號18

egrep -o "\((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]|([0-9])|(2[0-9])|(3[0-1]))([0-9]){3}([0-9]|X)\>"

4、用擴展正則表達式表示郵箱

qq郵箱:

egrep -o "\<[1-9][0-9]{4,9}@qq.com\>"

所有郵箱 :

egrep -o "\<([[:alnum:]]+(-|_)*[[:alnum:]]*)\>@([[:alnum:]]\.)+[[:alnum:]]+"

原創文章,作者:liushaoshao,如若轉載,請注明出處:http://www.www58058.com/30569

(0)
liushaoshaoliushaoshao
上一篇 2016-08-08
下一篇 2016-08-08

相關推薦

  • hello! 我的博客第一站

    大家好!  這是我進博客的第一天,一個剛進來的新司機。在這里我就不秀我的車技了,只希望各位老司機開車不要太快,我暈車      —— 生命不息,奮斗不止

    Linux干貨 2017-07-11
  • Mariadb數據庫復制系列(五):基于SSL的復制

       實驗五:基于SSL的主從復制功能的實現 在mysql服務器之間復制數據,默認情況下都是基于明文的,在有些場景中,明文傳輸會造成嚴重的數據安全隱患,因此,需要對mysql服務器之間的復制時的傳輸進行加密,傳輸加密方式可以基于SSL的會話進行 1、實驗環境 2、私有CA的搭建 3、在主節點node72上生成證書簽署請求、發送到私有CA服務器 4、在從節點n…

    Linux干貨 2016-11-24
  • CentOS 6.5 LVM磁盤管理學習筆記(二)

    ACTIVE            '/dev/vg51cto/LogVol04' [22.80 GiB]inherit  ACTIVE       …

    Linux干貨 2016-08-29
  • LVM: Logical Volume Manager 邏輯卷管理

      一、LVM介紹         LVM: Logical Volume Manager, Version: 2             …

    Linux干貨 2016-09-19
  • 文本處理相關工具

    文本工具       操作系統中,文本的處理這一操作,比如操作一些內容,查看一些內容等等這些東西在linux中都得借助工具來完成對文本的操作。下面來說說對文本處理的工具;  其中:        查看文件內容工具:more、less、cat     &nbsp…

    Linux干貨 2016-08-05
  • 運維必備的”武器庫”

    作者總結的干貨,拿來分享給大家,滿滿的全是干貨 Blog:http://www.simlinux.comWeibo:http://weibo.com/geekwolf Bootstrapping: Kickstart、Cobbler、rpmbuild/xen、kvm、lxc、Openstack、 Cloudstack、Opennebula、Eucalyplu…

    Linux干貨 2015-03-13
欧美性久久久久