headbash
默認輸出文件內容的前10行app
NAMEide
- output the first part of filesthis
SYNOPSIS( 大綱,摘要)spa
- head [option]... [file]...rem
參數it
-n 指定行io
-c --bytesast
-v 顯示文件的文件名class
#顯示前5行 head -n 5 /etc/inittab head -5 /etc/inittab #只須要掌握這條命令便可
#顯示前5個字節 head -c 5 /etc/inittab
#除去最後10行,其它內容都輸出 head -n -10 /etc/inittab
#同時查看多個文件的前10行 head /etc/inittab /etc/services
#顯示文件的文件名 head -v /etc/inittab
tail
默認輸出文件內容的後10行
NAME
- output the last part of files
SYNOPSIS
- tail [option]... [file]...
參數
-n 指定行
-f --follow
output appended data as the file grows
#顯示後5行 tail -5 /etc/inittab
#動態實時的顯示文件的內容 tail -f test.log tailf test.log #tailf是單獨的命令:follow the growth of a log file
cut
切割:cut命令默認是以tab鍵做爲分割符,可是,只支持單個分割符!
NAME
- remove sections(區段) from each line of files
SYNOPSIS
- cut option... [file]...
參數
-b --bytes 字節
-c --characters 字符
#1個英文字符 = 1個字節
#1箇中文字符 = 2個字節
-d --delimiter 指定分割符(默認是以tab鍵做爲分割符)
-f --fields 指定分割的區域(常和-d參數配合使用)
#練習素材 echo "I am oldboy my qq is 1234567" >test.txt
#按字節切割(按字符切割操做同理,若是有中文,必定要指定-c參數,不然會出現亂碼) cut -b 3 test.txt cut -b 3-4 test.txt cut -b -4 test.txt cut -b 4- test.txt cut -b 1,4- test.txt cut -b -4,4- test.txt
#切割出來指定的域 head -1 /etc/passwd|cut -d : -f4
#修改練習素材 cat >test.txt<<EOF thisistabline. this is space line. #把tab鍵顯示出來 cat -T test.txt #參數T:顯示tab鍵 ^I sed -n 1 test.txt #參數n:取消默認輸出 參數L:打印不可見字符 \t(tab) $(空格) #cut命令默認是以tab鍵做爲分割符(awk命令默認是以空格做爲分割符) cut -f2-3 test.txt #指定空格爲分割符 cut -d ' ' -f2-3 test.txt #注意:cut命令只支持單個分割符!