Linux 查看日志命令tail的用法
tail 命令可用于查看文件的内容。
最常用到的是参数 -f ,用于查阅正在改变的日志文件。
命令格式:
tail [参数] [文件]
参数:
- -f 循环读取,监视文件的尾部内容(默认10行,相当于增加参数 -n 10)
- -q 不显示处理信息
- -v 显示详细的处理信息
- -c<数目> 显示的字节数
- -n<行数> 显示文件的尾部 n 行内容
- –pid=PID 与-f合用,表示在进程ID,PID死掉之后结束
- -q, --quiet, --silent 从不输出给出文件名的首部
- -s, --sleep-interval=S 与-f合用,表示在每次反复的间隔休眠S秒
可以执行命令tail --help就能看到tail命令介绍
-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=Nwith --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显示版本信息并退出
其中 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特别适合那些便携机上跟踪日志文件。
如果遇到日志文件较大的时候,通常会输出的行数来查看日志:
// 默认显示 log 文件的最后 10 行
tail test.log// 显示 log 文件的最后 10 行,同时跟踪名为文件的增长情况,直到您按下(Ctrl-C)组合键停止显示。
tail -f test.log// 显示 log 文件的最后 n 行,同时跟踪名为文件的增长情况,直到您按下(Ctrl-C)组合键停止显示。
tail -nf test.log// 显示文件的最后 10 行
tail -n 10 filename// 文件的第 9 行不显示,显示第 10 行到末尾行
tail -n -10 filename// 显示文件的第 10 行到末尾行
tail -n +10 filename逆序显示filename最后10行。
tail -r -n 10 filename// 显示第20行至末尾
tail +20 test.log// 显示最后10个字符
tail -c 10 test.log
退出:
按下CTRL+C。
Linux 查看日志命令tail的用法相关推荐
- Linux查看日志命令(4种常见方式)
第一种:查看实时变化的日志(比较吃内存) 最常用的: tail -f filename (默认最后10行,相当于增加参数 -n 10) Ctrl+c 是退出tail命令 其他情况: tail -n 2 ...
- linux查看日志命令_查看log日志基础命令
一.tail命令 tail -f test.log 可以动态的查看服务器运行状态的日志 head -n 5 test.log 显示top 5行 tail -n 5 test.log 显示last 5行 ...
- linux 查看日志命令总结
目录 单纯的查看 head tail cat tac 综合查看 more less grep,awk,sed三剑客 grep sed awk 查找文件命令 whereis find locate 单纯 ...
- linux 阅读日志命令 tail
来源:http://www.weiruoyu.cn/?p=643 查看文件内容的特殊方法 相信最基本的cat.more和less你已经很熟悉了,如果有特殊的要求呢: 1. 如果你只想看文件的前5行,可 ...
- linux学习查看日志命令
linux学习查看日志命令 tail -f linux学习日 志 文 件 说 明 /var/log/maillog 与邮件相关的日志信息 /var/log/secure 与安全相关的日志信息 /var ...
- linux view查看日志命令,linux查看日志文件内容命令tail、cat、tac、head、echo、vi
linux查看日志文件内容命令tail.cat.tac.head.echo tail -f test.log 你会看到屏幕不断有内容被打印出来. 这时候中断第一个进程Ctrl-C, --------- ...
- java查看日志命令_[Java教程]【Linux】linux查看日志文件内容命令tail、cat、tac、head、echo...
[Java教程][Linux]linux查看日志文件内容命令tail.cat.tac.head.echo 0 2017-11-14 12:00:29 linux查看日志文件内容命令tail.cat.t ...
- linux view查看日志命令,【Linux】linux查看日志文件内容命令tail、cat、tac、head、echo...
linux查看日志文件内容命令tail.cat.tac.head.echo tail -f test.log 你会看到屏幕不断有内容被打印出来. 这时候中断第一个进程Ctrl-C, --------- ...
- linux查看日志文件内容命令tail、cat、tac、head、echo、vi
linux查看日志文件内容命令tail.cat.tac.head.echo tail -f test.log 你会看到屏幕不断有内容被打印出来. 这时候中断第一个进程Ctrl-C, --------- ...
- linux查看日志的几种命令,Linux查看日志三种命令(转载)
第一种:查看实时变化的日志(比较吃内存) 最常用的: tail -f filename (默认最后10行,相当于增加参数 -n 10) Ctrl+c 是退出tail命令 其他情况: tail -n 2 ...
最新文章
- java中注解的使用_java中注解的使用
- Thread的start()和join()方法
- 我是该高兴呢还是悲伤呢?
- robot:List变量的使用注意点
- pthreads v3下的worker和pool的使用
- c语言生日快乐音乐程序,89S51演奏生日快乐的歌曲c程序
- Caused by: org.apache.thrift.TApplicationException: Required field ‘filesAdded‘ is unset
- 最喜欢的动画片《长江7号爱地球》
- android报错:Only the original thread that created a view hierarchy can touch its views.
- ubuntu18.04下EnlightenGAN运行过程记录
- 解决Office在修改安装路径后,提示“操作系统当前配置不能运行此程序”的问题
- Vue+ElementUI table表格分页
- Python爬虫 scrapy框架爬取某招聘网存入mongodb解析
- 7K7K小游戏《黑客是怎样炼成的》攻略
- Python也能聊微信
- Node——微信支付 V3接口
- 为什么学完这个他们都跳槽/涨薪了?
- (四)Git——团队协作
- 冬季给孩子熬粥有讲究
- VMware vSphere Replication 8.5部署及使用教程