【基础】tail命令查看日志
一、tail 命令介绍
tail 命令可以将文件指定位置到文件结束的内容写到标准输出。
如果你不知道tail命令怎样使用,可以在命令行执行命令tail --help就能看到tail命令介绍和详细的参数使用介绍,内容如下(我帮大家翻译了一下)。
[root@yanggongzi ~]# tail --help
Usage: tail [OPTION]... [FILE]...
Print the last 10 lines of each FILE to standard output.
With more than one FILE, precede each with a header giving the file name.
With no FILE, or when FILE is -, read standard input.
将每个文件的最后10行打印到标准输出。
如果有多个文件,在每个文件之前都有一个给出文件名的头文件。
没有文件,或者当文件为-时,读取标准输入。
Mandatory arguments to long options are mandatory for short options too.
长选项必须用的参数在使用短选项时也是必须的。
-c, --bytes=K output the last K bytes;
or use -c +K to output bytes starting with the Kth of each file
输出最后的 K 个字节;
或者使用 -c +K 从每个文件的第K字节开始打印。
-f, --follow[={name|descriptor}]
output appended data as the file grows;
an absent option argument means 'descriptor'
随着文件的增长,输出附加数据;(动态输出最新的信息);
没有选项参数意味着“描述符”
-F same as --follow=name --retry
与 --follow=name --retry 作用相同
-n, --lines=K output the last K lines, instead of the last 10;
or use -n +K to output starting with the Kth
输出最后的K行,而不是最后的10行;
或者使用-n +K从第K个开始输出
--max-unchanged-stats=N
with --follow=name, reopen a FILE which has not changed size after N (default 5) iterations to see if it has been unlinked or renamed (this is the usual case of rotated log files);
with inotify, this option is rarely useful
使用——follow=name,在N次(默认为5次)迭代后,重新打开一个大小没有改变的文件,看看它是否被解除链接或重命名(这是旋转日志文件的常见情况);
对于inotify,这个选项很少有用
--pid=PID with -f, terminate after process ID, PID dies
与“-f”选项连用,当指定的进程号的进程终止后,自动退出tail命令
-q, --quiet, --silent never output headers giving file names
当有多个文件参数时,不输出各个文件名
--retry keep trying to open a file if it is inaccessible
即是在tail命令启动时,文件不可访问或者文件稍后变得不可访问,都始终尝试打开文件。使用此选项时需要与选项“——follow=name”连用
-s, --sleep-interval=N
with -f, sleep for approximately N seconds (default 1.0) between iterations;
with inotify and --pid=P, check process P at least once every N seconds
与“-f”选项连用,指定监视文件变化时间隔的秒数(默认为1.0);
使用inotify和-pid=P,每N秒检查进程P至少一次
-v, --verbose always output headers giving file names
当有多个文件参数时,总是输出各个文件名
--help display this help and exit
显示此帮助信息并退出
--version output version information and exit
显示版本信息并退出
If the first character of K (the number of bytes or lines) is a '+',
print beginning with the Kth item from the start of each file, otherwise,
print the last K items in the file. K may have a multiplier suffix:
b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.
如果K前面的字符(字节数或行数)是'+',每个文件从第K项开始打印,否则,打印文件中最后的K项。K可能有一个乘数后缀:b 512,kB 1000,K 1024,MB 1000 1000,M 1024 1024,GB 1000 1000,G 1024 1024 1024,等等,对于T,P,E,Z,y。
With --follow (-f), tail defaults to following the file descriptor, which
means that even if a tail"ed file is renamed, tail will continue to track
its end. This default behavior is not desirable when you really want to
track the actual name of the file, not the file descriptor (e.g., log
rotation). Use --follow=name in that case. That causes tail to track the
named file in a way that accommodates renaming, removal and creation.
使用——follow (-f), tail默认跟随文件描述符,这意味着即使重命名了尾部文件,tail也将继续跟踪其尾部。
当您真正想要跟踪文件的实际名称而不是文件描述符(例如,日志旋转)时,这种默认行为是不可取的。
在这种情况下使用——follow=name。这将导致tail以一种适合重命名、删除和创建的方式跟踪已命名文件。
二、tail 命令使用示例
1、输出最后200个字符
tail -c 200 test.log
2、从第900个字符开始输出,一直到最后
tail -c +900 test.log
3、输出最后20行
tail -n 20 test.log
4、从第36行开始输出,一直到最后
tail -n +36 test.log
5、输出指定文件的最后十行,同时继续监视文件内容有无变化,新增内容会继续输出,直到按下 [Ctrl-C] 组合键退出
tail -f test.log
6、指定多个文件并输出文件名
tail -v test1.log test2.log
7、指定多个文件不输出文件名
tail -q test1.log test2.log
三、tailf、tail -f、tail -F 的区别
tail -f
等同于–follow=descriptor,根据文件描述符进行追踪,当文件改名或被删除,追踪停止tail -F
等同于–follow=name --retry,根据文件名进行追踪,并保持重试,即该文件被删除或改名后,如果再次创建相同的文件名,会继续追踪tailf
等同于tail -f -n 10(貌似tail -f或-F默认也是打印最后10行,然后追踪文件),与tail -f不同的是,如果文件不增长,它不会去访问磁盘文件,所以tailf特别适合那些便携机上跟踪日志文件,因为它减少了磁盘访问,可以省电
当我们设置了滚动日志时,需要持续实时监控最新的日志输出,那么就要用tail -F,而不能用tailf 和 tail -f。因为当日志xxx.log达到了设定阈值重命名成了xxx01.log时,后两个命令追踪的还是xxx01.log文件而不是新创建的xxx.log文件,这时就不能继续监控最新日志了。
四、常用快捷键
【Ctrl】+【S】 暂停刷新。
【Ctrl】+【Q】继续刷新。
【Ctrl】+【C】退出 tail 命令。
【基础】tail命令查看日志的更多相关文章
- 菜鸟学Linux命令:tail命令 查看日志
tail 命令用于显示指定文件末尾内容,不指定文件时,作为输入信息进行处理. tail命令常用来查看日志文件.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filenam ...
- tail命令 查看文件尾部 输出文件后n行,默认查看文件的后10行
tail命令 查看文件尾部 用于查看日志 默认查看文件的后10行 -n 3 数字 也可以忽略-n 直接加数字 tail 3 查看文件后3行 [root@localhost ~]# tail /e ...
- tail 命令 查看Tomcat目录下日志的最后几行的方法
工作中需要查看日志信息,进行排错,但是面对上万行的错误日志,从头开始往后看,比较浪费时间,所有使用tail命令会节省不少时间. 1.命令 tail - n opt/tomcat/logs/ca ...
- Linux的tail命令查看文件
小文件一般用cat 查看,但是如果文件内容过多,用cat就不合适了 可以用tail命令 # 默认显示文件最后十行 tail a.txt # 监视文件的尾部内容,默认十行, 可以-n 20显示20行 ...
- linux命令查看日志
首先介绍几个日志查看种常用的简单命令: 1.tail tail 命令可用于查看文件的内容,有一个常用的参数 -f 常用于查阅正在改变的日志文件. tail -f filename 会把 filenam ...
- 一、less命令查看日志
查看日志时,一般用less满足大部分的需求. 使用命令格式: less [要查看的文件名] 例如:less LOG.20201211 中间加参数命令格式 less 参数 [要查看的文件名] 例如:查看 ...
- Mysql: mysqlbinlog命令查看日志文件
想查看mysql的binlog文件,但是裸的binlog文件是无法直视的,mysqlbinlog这个工具是用来查看binlog文件内容的(使用方式man mysqlbinlog查看),但是使用mysq ...
- Linux常用命令查看日志
cattail -f日 志 文 件 说 明 /var/log/message 系统启动后的信息和错误日志,是Red Hat Linux中最常用的日志之一 /var/log/secure 与安全相关的日 ...
- Windows使用tail命令跟踪日志
我们知道如果是Unix/Linux环境可以直接使用 tail -f xxx.log即可. 但是Windows并没有自带这个命令,不过从网上可以找到tail.zip 实测可以将其解压放在C:\Windo ...
随机推荐
- Linux用户配置文件、口令配置文件、组配置文件
1.用户配置文件:保存用户信息 /etc/passwd 2.口令配置文件 /etc/shadow 每一行解释:登录名:加密口令:最后一次修改时间:最小时间间隔:最大时间间隔:警告时间:不活动时间:失效 ...
- Docker Explore the application
https://docs.docker.com/docker-for-mac/#explore-the-application Open a command-line terminal and t ...
- OC之判断数组最大最小值
超简单的筛选方法 array为你筛选的数组 NSNumber * max = [Array valueForKeyPath:@"@max.floatValue"]; NSNumbe ...
- 攻防世界Web_easytornado
题目: 解题思路: 题目就三个txt文本文件 , 由python_template_injection这篇随笔中了解到tornado也是python web应用程序模板的一种,应该也是考查模板注入. ...
- 【第一期百题计划进行中,快来打卡学习】吃透java、细化到知识点的练习题及笔试题,助你轻松搞定java
[快来免费打卡学习]参与方式 本期百题计划开始时间:2022-02-09,今日打卡题已在文中标红. 0.本文文末评论区打卡,需要登录才可以打卡以及查看其他人的打卡记录 1.以下练习题,请用对应的知识点 ...
- Renix软件如何添加VLAN头部——网络测试仪实操
一.添加VLAN头部 打开Renix软件,连接机箱, 预约端口 添加VLAN头部,选中"IPv4 Header"右键选择"Insert Before",会弹出& ...
- 如何让测试RFC2544更便捷——RFC2544测试实操
关键词:RFC2544:吞吐量测试:时延测试:丢包率:背靠背. 作为一名网络测试人员,大家肯定熟知一个测试标准,那就是RFC2544,RFC2544通过提供一个测试网络设备的测试标准,并规定了一系列测 ...
- Tabluea、Smartbi可视化仪表盘创建流程图分享
你知道Tableau.Smartbi在可视化仪表盘制作步骤上有何差异吗?下面一起来了解吧~ 根据上面的流程图我们可以了解到,不同于Smartbi是在同一界面即可完成的,Tableau是由很多个工作表组 ...
- EasyUI Datagrid 数据网格 点击选中行 再次单击取消选中行
适用于jquery-easyui-1.9.15版本: 在项目中全局搜索: opts.singleSelect==true 或者在jquery.easyui.min.js中搜索: opts.single ...
- WPF中使用OpenFileDialog打开文件
添加Microsoft.Win32程序集 private void OnOpenFile(object sender, EventArgs e) { OpenFileDialog openFileDi ...