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
下一篇 2016-08-08

相關推薦

  • 磁盤及文件系統管理

    I/O Ports: I/O設備地址文件的處理方式:open,read,write,close設備類型:    塊設備:block,存取單位“塊”,磁盤    字符設備:char,存取單位“字符”,鍵盤設備文件:關聯至一個設備驅動程序,進而能夠跟與之對應硬件設備進行通信設備號碼: &nbs…

    學員作品 2016-08-30
  • 馬哥教育網絡班20期+第10周博客作業

    4、寫一個腳本   (1) 能接受四個參數:start, stop, restart, status    start: 輸出“starting 腳本名 finished.”    …   (2) 其它任意參數,均報錯退出;     #!bin/b…

    學員作品 2016-12-05
  • 馬哥團隊帶你領略阿里風景

    馬哥團隊帶你揭秘互聯網巨頭公司—阿里巴巴 繼馬哥團隊騰訊一行之后,4月中旬我們又來到了坐落于杭州的另一個互聯網巨頭公司。 波濤萬里長江水,帶你入杭州。 真情伴你走,春色為你留。 西湖煙水茫茫,百頃風潭,十里荷香。 風景甚好,怎能不去杭州的阿里巴巴轉轉呢? 帶著“淡妝”,走,跟著我們前行…… 馬哥更是笑道:“我們這次來是和馬云談合作的!讓我們培訓出來的更多同學…

    學員作品 2015-04-29
  • 文本處理工具筆記

    1.文件查看相關命令      (1)cat命令      cat [OPTION]… [FILE]…      -E:顯示行結束符      -n:對顯示除的每一行進行編號 …

    學員作品 2016-08-10
  • 關于shell變量計算中單中括號與雙中括號、單引號與雙引號的一些看法

      單中括號是比較基本的變量計算及數值比較的方法,一般情況下已經足夠使用;雙中括號是擴展的數值比較方法,里面的數值計算也相對來說復雜些。這里我推薦大家平常工作中使用單中括號即可,滿足日常的工作,不做運維開發的話,雙括號方面涉及不多。   這里我還得提下單括號與雙括號,這里也是我經常混淆的地方,其實理解了也就輕松多了。單括號是對一段比較長的…

    學員作品 2016-08-15
  • Selinux的基本命令及練習

    配置SELinux 相關命令:       getenforce: 獲取selinux當前狀態       sestatus :查看selinux狀態      &nbs…

    學員作品 2016-09-19
欧美性久久久久