• cutbash
語法:[root @test /root ]# cut -d "分隔字符" [-cf] fieldsspa
參數說明:排序
-d :後面接的是用來分隔的字符,預設是『空格符』token
-c :後面接的是『第幾個字符』字符串
-f :後面接的是第幾個區塊?it
範例:ast
[root @test /root]# cat /etc/passwd | cut -d ":" -f 1class
將 passwd 這個文件裏面,每一行裏頭的 : 用來做爲分隔號,而列出第一個區塊!也就是姓名所在啦!test
[root @test /root]# last | cut -c1-20file
將 last 以後的數據,每一行的 1-20 個字符取出來!
• sort
語法:
[root @test /root ]# sort [-t 分隔符] [(+起始)(- 結束)] [-nru]
參數說明:
-t 分隔符:使用分隔符來隔開不一樣區間,預設是 tab +start -end:由第 start 區間排序到 end 區間
-n :使用『純數字』排序(不然就會以文字型態來排序)
-r :反向排序
-u :相同出現的一行,只列出一次!
範例:
[root @test /root]# cat /etc/passwd | sort
將列出來的我的帳號排序!
[root @test /root]# cat /etc/passwd | sort -t: +2n
將我的帳號中,以使用者 ID 來排序(以 : 來分隔,第三個爲 ID ,但第一個代號爲 0 之故)
[root @test /root]# cat /etc/passwd | sort -t: +2nr
反相排序!
• wc
語法:
[root @test /root ]# wc [-lmw]
參數說明:
-l :多少行(line)
-m :多少字符(char)
-w :多少字(word)
範例:
[root @test /root]# cat /etc/passwd | wc -l
這個文件裏頭有多少行?
[root @test /root]# cat /etc/passwd | wc -w
這個文件裏頭有多少字!?
• uniq
這個指令用來將『重複的行刪除掉只顯示一個』
語法:
[root @test /root ]# uniq
範例:
[root @test /root]# last | cut -d" " -f1 | sort | uniq
• tee
命令重定向到文件的同時將數據顯示在屏幕上
語法:
[root @test /root ]# last | tee last.list | cut -d " " -f1
範例:
[root @test /root]# last | tee last.list | cut -d " " -f1
• tr
語法:
[root @test /root ]# tr [-ds] SET1
參數說明:
-d :刪除 SET1 這個字符串
-s :取代掉重複的字符!
範例:
[root @test /root]# last | tr '[a-z]' '[A-Z]'
<==將小寫改爲大寫
[root @test /root]# cat /etc/passwd | tr -d :
<== : 這個符號在 /etc/passwd 中不見了!
[root @test /root]# cat /home/test/dostxt | tr -d '\r' > dostxt-noM
• split
語法:
[root @test /root ]# split [-bl]
輸入文件 輸出文件前導字符
參數說明:
-b :以文件 size 來分
-l :以行數來分
範例:
[root @test /root]# split -l 5 /etc/passwd test
<==會產生 testaa, testab, testac... 等等的文件
說明:在 Linux 底下就簡單的多了!你要將文件分割的話,那麼就使用 -b size 來將一個分割的文件限制其大小,若是是行數的話,那麼就使用 -l line 來分割!
管線命令在 bash 的連續的處理程序中是至關重要的!另外,在 log file 的分析當中也是至關重要的一環。
管道輸送到一個命令的標準輸入能夠使用標準輸入參數」-「 進行更仔細的控制.如cat命令的示例
eg: sort mylist | more
sort mylist | cat –n | lpr
pwd | cat – mylist | lpr