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

相關推薦

  • linux同時創建多個目錄

    mkdir -p a_{c,d} b_{c,d} mkdir 同時創建多個文件夾 mkdir -p  mylinux/{bin,boot/grub,dev,etc/{rc.d/init.d,sysconfig/network-scripts},lib/modules,lib64,proc,sbin,sys,tmp,usr/local/{bin,sb…

    2017-08-28
  • 馬哥教育網絡班21期+第7周課程練習

    1、創建一個10G分區,并格式為ext4文件系統;    (1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl; [root@centos ~]# mke2fs -t ext4 -b 2048 -m 2&…

    Linux干貨 2016-08-01
  • Network Teaming網絡組總結

    一、Network Teaming網絡組的創建 第一步;準備工作,建立兩個網絡接口eth0、eth1,把原有網卡配置文件刪除; 命令:cd /etc/sysconfig/network-scripts                rm -rf ifcfg-* &nbs…

    2017-03-26
  • linux 目錄結構

    該文章主要來自于網絡資料進行整理 目錄結構參考地址: http://www.iteye.com/topic/1125162 http://yangrong.blog.51cto.com/6945369/1288072 http://itlab.idcquan.com/linux/administer/939529_1.html http://itlab.id…

    系統運維 2015-12-19
  • 記一次CentOS7內核kernel的刪除重裝

    人生在于折騰,學習Linux更要多多折騰。在一次折騰中吸取教訓,更易于記憶。 今天我們來折騰Linux的內核:刪除系統內核后,通過光盤進行kernel的重安裝。 友情提示:請在虛擬機環境進行,折騰前務必做好系統快照。慎重! 環境 本次系統環境是如下圖: 刪除 我們先到/boot目錄下,強制刪除kernel文件: 重啟PC,此時系統報錯找不到內核文件,無法登錄…

    Linux干貨 2016-08-24
  • N25第六周作業

    vim編輯器 基本模式: 編輯模式,命令模式 輸入模式 末行模式: 內置的命令行接口;   打開文件: # vim [options] [file ..] +#:打開文件后,直接讓光標處于第#行的行首; +/PATTERN:打開文件后,直接讓光標處于第一個被PATTERN匹配到的行的行首;   模式轉換: 編輯模式:默認模式 編輯模式 &…

    Linux干貨 2017-02-15
欧美性久久久久