Linux学习笔记6 cat,tac,more,less,head,tail

来源:互联网 发布:爱上学软件下载 编辑:程序博客网 时间:2024/05/01 16:32

1.cat 查看文本内容

选项

  • -n: 显示行号
[root@localhost tmp]# cat -n /etc/issue     1  CentOS release 6.8 (Final)     2  Kernel \r on an \m     3
  • -E: 显示行尾结束符$
[root@localhost tmp]# cat -E /etc/issueCentOS release 6.8 (Final)$Kernel \r on an \m$$

2.tac 反向查看文本内容

[root@localhost tmp]# tac /etc/issueKernel \r on an \mCentOS release 6.8 (Final)

3.more:

查看文件内容 快捷键和man命令相同,查看文本内容最后自动退出

4. less

查看文件内容 快捷键和man命令相同, q键退出

5.head

查看文件前几行(默认前10行)

例子

[root@localhost tmp]# echo -e "1\n2\n3\n4\n5\n6\n7\n8\n9\n10"> demoecho -e "1\n2\n3\n4\n5\n6\n7\n8\n9\n10">> demo[root@localhost tmp]# head -5 demo12345[root@localhost tmp]# head -n 5 demo12345

6.tail:

选项

  • -f: 打印文件新增的内容

例子

查看文件尾部几行(默认尾部10行)

[root@localhost tmp]# tail -5 demo678910[root@localhost tmp]# tail -n 5 demo678910

-f选项的作用:

[root@localhost tmp]# tail -f demo12345678910新开一个命令行,执行以下命令:[root@localhost ~]# echo "11">>/tmp/demo发现上面的命令终端尾部打印了11字符串
0 0