查看整个文件
cat [filename]
例如:查看/home/user/test.txt
cat /home/user/test.txt
查看开头几行
head -n [rows] [filename]
例如:查看/home/user/test.txt的前20行
head -n 20 /home/user/test.txt
查看末尾几行
tail -n [rows] [filename]
例如:查看/home/user/test.txt的最后10行
tail -n 10 /home/user/test.txt
查看中间几行
方法一:
cat [filename]| head -n [endRow] | tail -n +[beginRow]
例如:查看/home/user/test.txt的10~20行
cat /home/user/test.txt| head -n 20 | tail -n +10
head -n 20 表示前20行
tail -n 10 表示后10行
tail -n +10 表示第10行之后的
方法二:
sed -n '[begin],[end]p' [filename]
例如:查看/home/user/test.txt的10~20行
sed -n '10,20p' /home/user/test.txt