Linux 第七天: (08月05日) 練習和作業

Linux 第七天: (08月05日) 練習和作業

 

 

 

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

ifconfig | tr -cs '[0-9].''\n' | sort -ut '.' -k3 -n 或
ifconfig | head -2 | tail -1 | cut -d: -f2 | cut -d " " -f1

 

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

df -h |tr -s ' ' ':'|cut -d: -f5 |tr -d % | sort -n

 

3 查出用戶UID最大值得用戶名,UID及shell類型

getent passwd | sort -t: -k3 -nr|cut -d: -f1,3,7|tail -1

 

4 查出/tmp權限, 以數字顯示

stat /tmp |head -4 |tail -1 |tr " " "\n" |head -2 |tail -1|tr -dc '[:digit:]'

 

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

netstat -nt|tr -s ' ' '|' |cut -d '|' -f5 |cut -d: -f1 |uniq -c|sort -n

 

統計/etc/init.d/functiongs每個單詞出現次數

cat /etc/init.d/functiongs | tr -cs '[:alpha:]''\n' | sort  | uniq -c | sort -n

 

掃描網段顯示主機IP

nmap -sP -v 10.1.252.210/24 | grep -B1 up | grep -v up

 

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

grep '^[sS].*' /proc/meminfo 或
grep -i '^s.*' /proc/meminfo 或
grep -e '^s.*' -e '^S.*' /proc/meminfo

 

2 顯示/etc/paswd 文件中不以/bin/bash結尾的行

grep -v /bin/bash& /etc/passwd

 

3 顯示用戶rpc默認的shell程序

grep '^rpc\>' /etc/passwd | cut -d : -f 7

 

4 找出/etc/passwd 文件中的兩位或三位數

grep "\<[1-9][0-9][0-9]\?\>" /etc/passwd 或
grep "\<[1-9][0-9]\{1,2\}\>" /etc/passwd 或
grep -w "[1-9][0-9][0-9]\?" /etc/passwd

 

5 顯示/etc/grup2.cfg文件中至少一個空白字符開頭的且后面有非空白字符的行

grep "^[[:space]]\+[^[:space:]].*" /etc/grub2.cfg

 

6 找出"netstat -tan"命令結果中以'LISTEN'后跟任意空白字符結尾的行

netstat -tan | grep 'LISTEN[[:space]]]*$'

 

7 添加用戶bash,testbash,basher,nologin(shell為/sbin/nologin),
  找出/etc/passwd文件中用戶名同shell名的行

useradd bash
useradd testbash
useradd basher
useradd nologin -s /sbin/nologin
grep '^\<\(.*\)\>.*/\1$' /etc/passwd 或
grep '^\<\(.*\)\>.*\<\1\>$' /etc/passwd

 

1 顯示root,mage,wang,的UID和默認shell

grep -E "^\<root\>|^\<mage\>|^\<wang\>" /etc/passwd|cut -d: -f3,7 或
grep -E "^(root|wang|mage)\>" /etc/passwd|cut -d: -f3,7 或
grep -E "^(root|wang|mage):" /etc/passwd|cut -d: -f3,7

 

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

egrep "^[[:almum:]_]+\(\)" /etc/tc.d/init.d/functions|

 

3 使用egrep取出/etc/rcd/initd/functions中基名

echo "/etc/rc.d/init.d/functions" | egrep -o"[^/]+/?$"

 

4 使用egrep取出/etc/rcd/initd/functions目錄名

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

 

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

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

 

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

([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]

 

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

ifconfig | grep -E -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])' 或

ifconfig | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'

 

正則表達式表示身份證號

^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$

 

正則表達式表示手機號

^[1][3|5|7|8][0-9]{9}$

 

正則表達式表示郵箱

^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$

 

正則表達式表示QQ號

[1-9][0-9]{5,11}

 

 

 

 

 

 

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

(0)
dengjiandengjian
上一篇 2016-08-08 09:22
下一篇 2016-08-08 09:22

相關推薦

  • 設計模式 ( 二十 ) 訪問者模式Visitor(對象行為型)

    特此說明:對訪問者模式理解不是特別透徹,若有誤,請指正,謝謝! 1.概述 在軟件開發過程中,對于系統中的某些對象,它們存儲在同一個集合collection中,且具有不同的類型,而且對于該集合中的對象,可以接受一類稱為訪問者的對象來訪問,而且不同的訪問者其訪問方式有所不同。 例子1:顧客在超市中將選擇的商品,如蘋果、圖書等放在購物車中,然后到收銀員處付款。在購…

    Linux干貨 2015-04-07
  • Shell 位置參數總結

    描述: 位置參數指的是shell腳本的命令行參數,同時也表示shell函數的額函數參數。 說明: 示例: #!/bin/sh echo "number:$#"     # 傳給腳本的參數個數 echo "scname:$0" &n…

    Linux干貨 2016-08-16
  • Linux基礎知識之RAID

    1、什么是RAID?     多個磁盤合成一個“陣列”來提供更好的性能、冗余,或者兩者都提供。2、RAID的優點?     提高IO 能力:         磁盤并行讀寫   &n…

    Linux干貨 2016-09-01
  • 8月20日軟件包管理

    軟件包管理 本章內容 軟件運行環境 軟件包基礎 Rpm包管理 yum管理 定制yum倉庫 編譯安裝 軟件運行環境 API:Application Programming Interface     POSIX:Portable OS 程序源代碼–>預處理–>編譯–>…

    Linux干貨 2016-08-21
  • 常用RAID級別介紹

    RAID是什么         磁盤陣列(Redundant Arrays of Independent Disks,RAID),磁盤陣列是將多個價格便宜的磁盤按照一定的組合方式組成具有高容量的磁盤組,按照不同的組合方式可以達到不同的效果,如:可以提升磁盤的存取效率,可提高磁盤的…

    Linux干貨 2016-02-14
  • 第十五周作業

    1、總結sed和awk的詳細用法; sed:     模式空間:sed是一種在線編輯器、行編輯器,一次處理一行內容,在處理時,把當前處理的行存儲在臨時緩沖區當中,并在該緩沖區中完成后續的處理,該緩沖區被稱為”模式空間”。     保持空間:在模式空間中處理完一行內容后會繼續處理下一行,但是對于處…

    Linux干貨 2017-04-18
欧美性久久久久