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命令只支持单个分割符!