8月5日課堂及課后作業

課堂作業

1.找出ifconfig命令結果中的IP地址

[root@localhost ~]# ifconfig |head -2|grep "inet" |tr " " ":"|cut -d: -f13

8月5日課堂及課后作業

2、找出df中磁盤利用率的數

[root@localhost ~]# df |tail -5|tr ' ' ':' |tr -s :|cut -d: -f5 |tr "%" " "

8月5日課堂及課后作業

簡便方法: [root@localhost ~]# df |tail -5 |tr -s " "|cut -d" " -f5 |tr -d %

注意:tr -s 是去掉相同的 tr -d 是刪除 tr -cd刪除取反的(忘記了,再記)

3、1.找出ifconfig命令結果中本機的所有ipv4地址

[root@localhost ~]# ifconfig |tr -cs '[0-9].' '\n' |sort -ut '.' -k3n

8月5日課堂及課后作業

4、查處分區空間使用率的最大百分比值

[root@localhost ~]# df |tr -s " "|tr " " ":"|cut -d: -f5|tr -d %|sort -n|tail -1

8月5日課堂及課后作業

5、查處用戶uid最大值的用戶名、uid及shell類型

[root@localhost ~]# getent passwd|cut -d: -f1,3,7|sort -t : -k2 -n|tail -1

8月5日課堂及課后作業

6、查處/tmp的權限,以數字方式顯示

[root@localhost ~]# stat /tmp|grep "Uid"|cut -d: -f2 |tr -cs [0-9] ' '

8月5日課堂及課后作業

方法二:[root@localhost ~]# stat /tmp|grep "Uid"|tr -cs [0-9] ' '|cut -d" " -f2

7、顯示/proc/meminfo文件中以大小s開頭的行(兩種方法)

[root@localhost ~]# grep -i '^s.*' /proc/meminfo 

[root@localhost ~]# grep  '^[Ss].*' /proc/meminfo

8月5日課堂及課后作業

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

[root@localhost ~]# grep -v "\(/bin/bash\)$" /etc/passwd

8月5日課堂及課后作業

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

[root@localhost ~]# getent passwd|grep '^rpc\>' |cut -d: -f7

8月5日課堂及課后作業

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

[root@localhost ~]# grep "\<[1-9]\{2,3\}\>" /etc/passwd

8月5日課堂及課后作業

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

[root@localhost ~]# grep "^[[:space:]]\+[^[:space:]].*" /etc/grub.conf

8月5日課堂及課后作業

12、找出‘netstat -tan’命令的結果中以‘LISTEN’后跟任意多個空白字符結尾的行

[root@localhost ~]# netstat -tan|grep "LISTEN[[:space:]]*$"

8月5日課堂及課后作業

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

[root@localhost ~]# grep "^\<\(.*\)\>.*\1$" /etc/passwd

8月5日課堂及課后作業

14、顯示三個用戶root,mage,wang的uid和默認shell

[root@localhost ~]# egrep "^(mage|wang|root)\>" /etc/passwd |cut -d: -f1,7

8月5日課堂及課后作業

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

[root@localhost ~]# egrep  "^[[:alpha:]_]*\(\)" /etc/rc.d/init.d/functions

8月5日課堂及課后作業

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

[root@localhost ~]# echo " /etc/rc.d/init.d/functions" |egrep -o "[^/]+/?$"

8月5日課堂及課后作業

17、使用egrep取出/etc/ec.d/init.d/functions的目錄名

[root@localhost ~]# echo " /etc/rc.d/init.d/functions" |egrep -o "(/.*/)"

8月5日課堂及課后作業

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

[root@localhost ~]# last |egrep -o "^root\>.*([[:digit:]]\.){3}[[:digit:]]" |tr -s '' |cut -d ' ' -f3|sort |uniq -c

19、利用擴展正則表達式分別表示0-9,10-99,100-199,200-249,250-255,顯示ifconfig命令結果中所有ipv4地址

[root@localhost ~]# ifconfig |egrep -o "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])"

8月5日課堂及課后作業

20、統計/etc/init.d/functions 文件中每個單詞出現的次數,并按頻率從高到低顯示

[root@localhost ~]# cat /etc/init.d/functions |tr -cs '[:alpha:]' "\n" |sort|uniq -c|sort -nr

8月5日課堂及課后作業

21、/etc/rc.d/init.d/functions或/etc/rc.d/init.d/functions/" 取目錄名

[root@localhost ~]# echo "/etc/rc.d/init.d/functions/" |sed 's@[^/]\+/\?$@@'

8月5日課堂及課后作業

22、正則表達式表示身份證(后續幾題暫時不會)

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

(1)
1515218807015152188070
上一篇 2016-08-08 16:15
下一篇 2016-08-08 16:15

相關推薦

  • 馬哥教育網絡班21期-第七周課程練習

    第七周 1、創建一個10G分區,并格式為ext4文件系統;    (1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl;    (2) 掛載至/data/mydata目錄,要求掛載時禁止程序自動…

    學員作品 2016-08-29
  • Linux學習總結及練習&day08-sed文本處理工具

    第一部分、Linux文本處理三劍客之sed(Stream EDitor)文本編輯工具     一、sed的基本功能工作原理     sed是一種流編輯器,它一次處理一行內容。處理時,把當前處理的行存儲在臨時緩沖區中,稱為“模式空間”(pattern space),接著用sed命令…

    Linux干貨 2016-08-10
  • 馬哥linux特推出“你學習,我買單—免費公開課”的活動

    馬哥linux特推出“你學習,我買單—免費公開課”的活動 為了感謝廣大linux愛好者對馬哥教育的一路陪伴和支持。時值五一佳節來臨之際,馬哥linux特推出“你學習,我買單—免費公開課”的活動,本期分享主題為:“Linux運維架構師成長必經之路”,后期我們將會不斷的推出更多免費精彩課程和大家一起分享, 具體報名方式以及問題咨詢,請加入…

    學員作品 2015-04-22
  • vim編輯器

    一、vim簡介    vi: Visual Interface,文本編輯器     文本: ASCII, Unicode     文本編輯種類:         行編輯器: sed…

    Linux干貨 2016-08-10
  • 第六次作業

    1 、取本機ip地址 Centos6.8 ifconfig | head -2|tail -1|cut -d: -f2|cut -d" " -f1 ifconfig | head -2|tail -1|cut&…

    學員作品 2016-08-10
  • Linux進程查看和管理及作業控制

    在linux系統中,內核的功用有:進程管理、文件系統、網絡功能、內存管理、驅動程序、安全功能等,在這眾多的模塊中,進程管理是相對重要的一環,即使不像文件系統和網絡功能那么復雜。在進程管理中,內核對進程的創建、切換、撤銷和調度都有很詳細的定義。  1、進程類型     守護進程:在系統引導過程中啟動的進程,跟終端無關的進…

    學員作品 2016-11-14
欧美性久久久久