Linux 命令(文件和目录管理 - tail)
来源:互联网 发布:黑莓q5软件下载 编辑:程序博客网 时间:2024/06/13 09:49
简述
有 head ( 头 ) 自然就有 tail ( 尾巴 ) - 首尾呼应,tail 的用法和 head 差不多类似。只不过是显示后面几行,预设也是显示 10 行,若要显示非 10 行,使用 -n
选项即可。
- 简述
- 命令介绍
- 命令选项
- 使用范例
命令介绍
命令名称
tail基本语法
tail [选项]… [文件]…功能描述
将每个文件的最后 10 行打印到标准输出。对于多个文件,每个前面都有一个给出文件名的标题。如果没有指定文件或者文件名为“-”,读取标准输入。
命令选项
-c, --bytes=K
输出最后 K 个字节 -f, --follow[={name|descriptor}]
当文件增长时,输出后续添加的数据 -F
和 --follow=name --retry
一样 -n, --lines=K
输出最后 K 行,而非默认的最后 10 行 --max-unchanged-stats=N
与 --follow=name
合用, --pid=PID
与 -f
合用,表示在进程 ID、PID 死掉之后结束。 -q, --quiet, --silent
从不输出给出文件名的首部 --retry
即使 tail 开始时就不能访问,或者在 tail 运行后不能访问,也仍然不停地尝试打开文件,--
只与 -f
合用时有用。 -s, --sleep-interval=N
与 -f
合用,表示在每次反复的间隔休眠 N 秒 -v, --verbose
总是输出给出文件名的首部 --help
显示帮助信息后退出 --version
输出版本信息后退出如果 K(字节或者行数)的第一个字符为‘+’, 那么从每个文件的开头算起的第 K 项开始显示,否则,显示该文件的最后 K 项。K 可以有一个倍数后缀:b 512,kB 1000,K 1024,MB 1000*1000,M 1024*1024,GB 1000*1000*1000,G 1024*1024*1024,对于 T、P、E、Z、Y 同样适用。
如果希望即时追查一个文件的有效名称而非描述内容(例如循环日志),默认的程序动作并不如你所愿。在这种场合可以使用 --follow=name
选项,它会使 tail 定期追踪打开给定名称的文件,以确认它是否被删除或被其它某些程序重新创建过。
使用范例
1.不使用任何选项执行 tail
默认情况下,将文件的最后 10 行打印到标准输出。
[root@localhost Python-3.5.2]# tail README Copyright (c) 1991-1995 Stichting Mathematisch Centrum. All rights reserved.See the file "LICENSE" for information on the history of this software,terms & conditions for usage, and a DISCLAIMER OF ALL WARRANTIES.This Python distribution contains *no* GNU General Public License (GPL) code,so it may be used in proprietary projects. There are interfaces to some GNUcode but these are entirely optional.All trademarks referenced herein are property of their respective holders.[root@localhost Python-3.5.2]#
2.输出最后 K 行的内容
如果要输出最后 K(这里为 5)行的内容,而非默认的最后 10 行,使用 -n
选项。
[root@localhost Python-3.5.2]# tail -n 5 README This Python distribution contains *no* GNU General Public License (GPL) code,so it may be used in proprietary projects. There are interfaces to some GNUcode but these are entirely optional.All trademarks referenced herein are property of their respective holders.[root@localhost Python-3.5.2]#
3.从第 K 行开始显示文件的内容
从第 K(这里为 218)行开始显示文件的内容,直至文件末尾。
# 查看文件 README 的内容[root@localhost Python-3.5.2]# cat -n README 1 This is Python version 3.5.2 2 ============================ 3 4 Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 5 2012, 2013, 2014, 2015, 2016 Python Software Foundation. All rights reserved. # 部分显示结果省略... 215 See the file "LICENSE" for information on the history of this software, 216 terms & conditions for usage, and a DISCLAIMER OF ALL WARRANTIES. 217 218 This Python distribution contains *no* GNU General Public License (GPL) code, 219 so it may be used in proprietary projects. There are interfaces to some GNU 220 code but these are entirely optional. 221 222 All trademarks referenced herein are property of their respective holders.# 从第 218 行开始显示文件 README 的内容,直至文件末尾。[root@localhost Python-3.5.2]# tail -n +218 README This Python distribution contains *no* GNU General Public License (GPL) code,so it may be used in proprietary projects. There are interfaces to some GNUcode but these are entirely optional.All trademarks referenced herein are property of their respective holders.[root@localhost Python-3.5.2]#
4.输出最后 K 个字节的内容
使用 -c
选项,可以指定显示文件的最后 K(这里为 5)个字节的内容。
[root@localhost Python-3.5.2]# tail -c 5 README ers.[root@localhost Python-3.5.2]#
5.当文件增长时,输出后续添加的数据
由于 /var/log/message.log 随时会有资料写入,想要让该档案在有资料写入时就立刻显示到屏幕上,就利用 -f
选项,可以一直侦测该档案,新加入的资料都会被显示到屏幕上,直到按下 Ctrl + C 才会离开。
[root@localhost Python-3.5.2]# tail -f /var/log/message.log
6.和其他命令组合使用
列出一个目录下的文件,如果内容过多,可以用 tail 来过滤显示,需要和管道符 |
结合起来。
[root@localhost Python-3.5.2]# ls -l总用量 34676-rw-r--r--. 1 wang wang 8464 6月 26 05:38 aclocal.m4drwxr-xr-x. 5 root root 79 9月 7 20:30 build-rwxr-xr-x. 1 wang wang 42856 6月 26 05:38 config.guess-rw-r--r--. 1 root root 835023 9月 7 15:06 config.log-rwxr-xr-x. 1 root root 40031 9月 7 15:06 config.status-rwxr-xr-x. 1 wang wang 35740 6月 26 05:38 config.sub-rwxr-xr-x. 1 wang wang 474932 6月 26 05:38 configure-rw-r--r--. 1 wang wang 155069 6月 26 05:38 configure.acdrwxrwxr-x. 18 wang wang 4096 6月 26 05:47 Docdrwxrwxr-x. 2 wang wang 20 6月 26 05:38 Grammardrwxrwxr-x. 2 wang wang 4096 6月 26 05:38 Include-rwxr-xr-x. 1 wang wang 7122 6月 26 05:38 install-shdrwxrwxr-x. 47 wang wang 8192 9月 7 20:29 Lib-rw-r--r--. 1 root root 21053416 9月 7 20:29 libpython3.5m.a-rw-r--r--. 1 wang wang 12767 6月 26 05:38 LICENSEdrwxrwxr-x. 8 wang wang 4096 6月 26 05:38 Mac-rw-r--r--. 1 root root 66393 9月 7 15:06 Makefile-rw-r--r--. 1 root root 58147 9月 7 15:06 Makefile.pre-rw-r--r--. 1 wang wang 58449 6月 26 05:38 Makefile.pre.indrwxrwxr-x. 2 wang wang 4096 9月 7 15:06 Miscdrwxrwxr-x. 11 wang wang 8192 9月 7 20:29 Modulesdrwxrwxr-x. 4 wang wang 4096 9月 7 20:28 Objectsdrwxrwxr-x. 2 wang wang 4096 9月 7 20:28 Parserdrwxrwxr-x. 4 wang wang 4096 6月 26 05:38 PCdrwxrwxr-x. 2 wang wang 4096 6月 26 05:38 PCbuilddrwxrwxr-x. 2 wang wang 4096 9月 7 20:30 Programs-rw-r--r--. 1 root root 26 9月 7 20:29 pybuilddir.txt-rw-r--r--. 1 root root 43899 9月 7 15:06 pyconfig.h-rw-r--r--. 1 wang wang 41897 6月 26 05:38 pyconfig.h.in-rwxr-xr-x. 1 root root 12284727 9月 7 20:29 pythondrwxrwxr-x. 3 wang wang 4096 9月 7 20:29 Python-rw-r--r--. 1 root root 3080 9月 7 15:14 python-config-rw-r--r--. 1 root root 2042 9月 7 15:14 python-config.py-rw-r--r--. 1 root root 61170 9月 7 15:14 python-gdb.py-rw-r--r--. 1 wang wang 8060 6月 26 05:38 README-rw-r--r--. 1 wang wang 99778 6月 26 05:38 setup.pydrwxrwxr-x. 22 wang wang 4096 6月 26 05:38 Tools# 列出最后 5 个文件[root@localhost Python-3.5.2]# ls -l | tail -5-rw-r--r--. 1 root root 2042 9月 7 15:14 python-config.py-rw-r--r--. 1 root root 61170 9月 7 15:14 python-gdb.py-rw-r--r--. 1 wang wang 8060 6月 26 05:38 README-rw-r--r--. 1 wang wang 99778 6月 26 05:38 setup.pydrwxrwxr-x. 22 wang wang 4096 6月 26 05:38 Tools
- Linux 命令(文件和目录管理 - tail)
- 【Linux文件目录命令】tail命令
- linux文件目录操作命令 tail
- linux命令学习-文件目录之tail命令
- Linux文件和目录管理相关命令
- linux 文件和目录管理--基础命令
- linux管理文件和目录的命令
- Linux 命令(文件和目录管理
- Linux 命令(文件和目录管理 - pwd)
- Linux 命令(文件和目录管理 - cd)
- Linux 命令(文件和目录管理 - ls)
- Linux 命令(文件和目录管理 - tree)
- Linux 命令(文件和目录管理 - mkdir)
- Linux 命令(文件和目录管理 - rmdir)
- Linux 命令(文件和目录管理 - tar)
- Linux 命令(文件和目录管理 - zip/unzip)
- Linux 命令(文件和目录管理 - gzip/gunzip)
- Linux 命令(文件和目录管理 - bzip2/bunzip2)
- CSS块级元素和行内元素
- 如何将报表系统集成到微信中?
- java 生成xml并转为字符串
- Sql Server 和 Oracle触发器的使用
- [数据结构]--二叉树以及Java实现
- Linux 命令(文件和目录管理 - tail)
- Oracle--表中插入数据优化
- Metron学习1_安全大数据分析框架 OpenSOC
- [Ubuntu] 安装 Nvidia 双显卡驱动
- 无中生有之突击NOIP(8)——更多算法(一)
- Code First Migrations更新数据库结构的具体步骤
- 进程间通信方式——共享内存
- 暨南大学Oracle OCM培训正在火热招生
- C#委托Delegate