8月5日作業

課堂練習:

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

[root@localhost ~]# ifconfig | tr -s " " |head -2 | tail -1 |cut -d: -f2 | cut -d" " -f1

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

[root@localhost ~]# df -h | tr -s " " |cut -d" " -f5 | sort -n

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

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

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

[root@localhost ~]# stat /tmp/ | tr -s " " |head -4 | tail -1| cut -d/ -f1 | cut -d"(" -f2

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

[root@localhost ~]# netstat -net |tr -s " " | cut -d" " -f5 |cut -d":" -f1 |uniq -c

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

[root@localhost ~]# grep -i ^s /proc/meminfo
[root@localhost ~]# grep  "^[s|S]" /proc/meminfo

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

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

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

[root@localhost ~]# grep "\<rpc" /etc/passwd -w |cut -d: -f7

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

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

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

[root@nzg7 ~]# grep "^[[:space:]]\+[^[:space:]]" /etc/grub2.cfg

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

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

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

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

13、顯示三個用戶root、mage、wang的UID和默認shell 

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

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

[root@localhost ~]# grep -E "^[_[:alpha:]]+\(\)" /etc/rc.d/init.d/functions -o

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

[root@localhost ~]# echo "/etc/sysconfig/network-scripts/ifcfg-eth0/" | grep -E "[^/]+/?$" -o |grep -E [^/]+ -o

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

[root@localhost ~]# echo "/etc/sysconfig/network-scripts/ifcfg-eno16777736/" | grep -E -o "^/.*[^/]" |grep -E -o "^/.*/"

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

[root@localhost ~]# last |tr -s " "|cut -d" " -f1,3 |grep "^root [[:digit:]]" |sort -n|uniq -c

18、利用擴展正則表達式分別表示0-9、10-99、100-199、 200-249、250-255 

[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]

19、顯示ifconfig命令結果中所有IPv4地址

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

課后作業:

1、取本機ip地址

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

2、取各分區利用率的數值

[root@localhost ~]# df -h | tr -s " " |cut -d" " -f5 |tr -sc [0-9] '\n' |sort -n

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

[root@localhost ~]# cat /etc/init.d/functions |grep -E "\<[[:alpha:]]+\>" -o |sort |uniq -c |sort -n

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

echo "/etc/rc.d/init.d/functions/" | grep -E "^/.*[^/]" -o |grep -E "^/.*/" -o

原創文章,作者:鬧鐘哥,如若轉載,請注明出處:http://www.www58058.com/31726

(0)
鬧鐘哥鬧鐘哥
上一篇 2016-08-15 14:31
下一篇 2016-08-15

相關推薦

  • 網絡管理及其一些網絡協議

    1,這周我們主要學的是有關網絡的相關知識;下面我就介紹一下我感覺重要的一些內容。 首先介紹的是計算機網絡協議的七層模型:從上到下依次分為:7,應用層(application):OSI模型的第七層,負責為操作系統或網絡應用程序提供訪問網絡服務的接口。                …

    2017-09-02
  • 第二周作業

    1 linux 常見的文件管理命令都有哪些?其常用的使用方法。 ls 文件列出命令   常見選項  -l 顯示長文本信息          -d 顯示當前目錄信息          -a 顯示所有文件信息     &nb…

    Linux干貨 2016-09-26
  • 文件的歸檔和壓縮

    文件的歸檔和壓縮 ?一、tar命令使用 ?二、其他壓縮方式 ?三、進程管理基本概念。 前言: 本節主要介紹文件的歸檔和壓縮相關方法。歸檔和壓縮有利于linux系統中文件的管理和磁盤空間的利用,善于利用歸檔和壓縮能為我們工作中帶來很多便捷。另外將簡單介紹進程的一些概念,方便下一節進程管理內容的學習。 一、 tar命令使用(tar命令用于文件…

    2017-04-16
  • rsyslog將日志記錄于MySQL中,并用loganalyzer進行分析日志

    1、首先來安裝lamp環境的支持,與其相關的軟件包      # yum -y install rsyslog-mysql mariadb-server php php-mysql php-gd httpd       說明:rsyslog-mysql在數據庫中生成一個庫文件,但這個文件需…

    Linux干貨 2016-10-23
  • 文件管理類命令常用使用方法及其相關示例演示

    文件管理類命令常用使用方法及其相關示例演示 cat chattr chmod chown cp ln locate lsattr mv rm tee touch umask whereis which 文件管理類命令常用使用方法及其相關示例演示 cat 使用語法:cat [-AbeEnstTuv][–help][–version] FILENAME&nb…

    Linux干貨 2016-11-05
  • 邏輯卷LVM

    邏輯卷LVM 簡介     在實際生產應用中,磁盤的分區的容量是固定不變的,當出現分區容量不足的情況,除了新加磁盤,還有沒有其他方法呢?    邏輯卷(LVM)的概念就出現了,全稱叫Logical Volume Manager。它的作用是允許對卷進行方便操作的抽象層,包括重新設定…

    Linux干貨 2017-08-12
欧美性久久久久