查看和编辑文件:head / tail / cat / Less
head 命令用于输出文件的前几行。参数 -n 制定要显示的行数(默认为10):
# prints the first three lines
[ andrew@pc01 ~ ]$ head -n 3 c
this
file
has
tail 命令用于输出文件的后几行。你可以用来获取最后的 n 行(如上),或者你可以使用 tail -n +N 从第N行开始获取直到文件末尾 。
# prints the end of the file, beginning with the 4th line
[ andrew@pc01 ~ ]$ tail -n +4 c
exactly
six
lines
cat命令用于连接文件列表,并将它们发送到标准输出流(通常是终端)。cat既可以单文件一起使用,也可多文件使用,通常用于快速查看,(警告:如果你这样使用cat,你可能会被判定 cat使用不当 ,但这没什么大不了,所以不要太担心。)
[ andrew@pc01 ~ ]$ cat a
file a
[ andrew@pc01 ~ ]$ cat a b
file a
file b
less 是另一个用于快速查看文件的命令- 它打开类似于 vim 文件的只读窗口。(另外,有一个 more 命令,但less命令提供比 more 更多功能,并且推荐使用 less .)想了解更多 more (或 less )
less 和
more在它们的用户手册上。
Server 社区 Wiki
关于 LearnKu