Linux日志查看(2)— tail 命令
2018-03-01 16:07
337 查看
tail命令可以将文件指定位置到文件结束的内容写到标准输出。使用
tail命令的
-f选项可以方便的查阅正在改变的日志文件。
tail -f filename会把文件里最尾部的内容显示在屏幕上,并且不断刷新,使你看到最新的文件内容。
NAME(名称) tail - output the last part of files 输出文件的最后一部分 SYNOPSIS(概要,大纲) tail [OPTION]... [FILE]... DESCRIPTION(描述) 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); 121f4 with inotify, this option is rarely useful 在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。
1、输出最后的100个字符
[root@peipei3514 usr]# tail -c 100 test.log 018-09-15 15:56:10:725 THERP 199 2018-09-16 15:57:16:725 DWMTJ 200 2018-09-17 15:58:13:725 PHKIZ
2、从第6500个字符开始输出,一直到最后
[root@peipei3514 usr]# tail -c +6500 test.log RBZDP 190 2018-09-07 15:48:11:724 PFMXT 191 2018-09-08 15:49:15:724 MWPPA 192 2018-09-09 15:50:06:724 UWRQM 193 2018-09-10 15:51:06:724 KOKZL 194 2018-09-11 15:52:22:724 WDKSI 195 2018-09-12 15:53:16:724 UXTIP 196 2018-09-13 15:54:06:724 XXTYN 197 2018-09-14 15:55:12:725 KWUAX 198 2018-09-15 15:56:10:725 THERP 199 2018-09-16 15:57:16:725 DWMTJ 200 2018-09-17 15:58:13:725 PHKIZ
3、输出最后的5行
[root@peipei3514 usr]# tail -n 5 test.log 196 2018-09-13 15:54:06:724 XXTYN 197 2018-09-14 15:55:12:725 KWUAX 198 2018-09-15 15:56:10:725 THERP 199 2018-09-16 15:57:16:725 DWMTJ 200 2018-09-17 15:58:13:725 PHKIZ
4、从第196行开始输出,一直到最后
[root@peipei3514 usr]# tail -n +196 test.log 196 2018-09-13 15:54:06:724 XXTYN 197 2018-09-14 15:55:12:725 KWUAX 198 2018-09-15 15:56:10:725 THERP 199 2018-09-16 15:57:16:725 DWMTJ 200 2018-09-17 15:58:13:725 PHKIZ
5、输出指定文件的最后十行,同时继续监视文件内容有无变化,新增内容会继续输出,直到按下 [Ctrl-C] 组合键停止该命令。
[root@peipei3514 usr]# tail -f test.log 191 2018-09-08 15:49:15:724 MWPPA 192 2018-09-09 15:50:06:724 UWRQM 193 2018-09-10 15:51:06:724 KOKZL 194 2018-09-11 15:52:22:724 WDKSI 195 2018-09-12 15:53:16:724 UXTIP 196 2018-09-13 15:54:06:724 XXTYN 197 2018-09-14 15:55:12:725 KWUAX 198 2018-09-15 15:56:10:725 THERP 199 2018-09-16 15:57:16:725 DWMTJ 200 2018-09-17 15:58:13:725 PHKIZ
6、指定多个文件并输出文件名
[root@peipei3514 usr]# tail -v test.log test2.log ==> test.log <== 191 2018-09-08 15:49:15:724 MWPPA 192 2018-09-09 15:50:06:724 UWRQM 193 2018-09-10 15:51:06:724 KOKZL 194 2018-09-11 15:52:22:724 WDKSI 195 2018-09-12 15:53:16:724 UXTIP 196 2018-09-13 15:54:06:724 XXTYN 197 2018-09-14 15:55:12:725 KWUAX 198 2018-09-15 15:56:10:725 THERP 199 2018-09-16 15:57:16:725 DWMTJ 200 2018-09-17 15:58:13:725 PHKIZ ==> test2.log <== 391 2019-03-27 22:00:38:800 GKAVS 392 2019-03-28 22:01:39:801 FZZQO 393 2019-03-29 22:02:36:801 SMEUF 394 2019-03-30 22:03:34:801 SMKWL 395 2019-03-31 22:04:35:801 VIADG 396 2019-04-01 22:05:24:801 VRGTH 397 2019-04-02 22:06:27:801 GDPIV 398 2019-04-03 22:07:30:801 WDEWY 399 2019-04-04 22:08:27:802 MXKMM 400 2019-04-05 22:09:42:802 EMIYR
7、指定多个文件不输出文件名
[root@peipei3514 usr]# tail -q test.log test2.log 191 2018-09-08 15:49:15:724 MWPPA 192 2018-09-09 15:50:06:724 UWRQM 193 2018-09-10 15:51:06:724 KOKZL 194 2018-09-11 15:52:22:724 WDKSI 195 2018-09-12 15:53:16:724 UXTIP 196 2018-09-13 15:54:06:724 XXTYN 197 2018-09-14 15:55:12:725 KWUAX 198 2018-09-15 15:56:10:725 THERP 199 2018-09-16 15:57:16:725 DWMTJ 200 2018-09-17 15:58:13:725 PHKIZ 391 2019-03-27 22:00:38:800 GKAVS 392 2019-03-28 22:01:39:801 FZZQO 393 2019-03-29 22:02:36:801 SMEUF 394 2019-03-30 22:03:34:801 SMKWL 395 2019-03-31 22:04:35:801 VIADG 396 2019-04-01 22:05:24:801 VRGTH 397 2019-04-02 22:06:27:801 GDPIV 398 2019-04-03 22:07:30:801 WDEWY 399 2019-04-04 22:08:27:802 MXKMM 400 2019-04-05 22:09:42:802 EMIYR
相关文章推荐
- linux查看日志文件内容命令sed、cat、tac、more、less、head、tail、echo 1、按时间查询 sed -n '/2017-09-20 14:00:/,/2017-
- linux查看日志文件内容命令tail、cat、tac、head、echo
- linux查看日志文件内容命令tail、cat、tac、head、echo
- linux查看日志文件内容命令tail、cat、tac、head、echo
- Linux查看日志文件命令tail
- linux查看日志文件内容命令tail、cat、tac、head、echo
- Linux常用查看日志命令tail
- linux查看日志文件内容命令tail、cat、tac、head、echo
- Linux常用查看日志命令tail
- Linux 常用查看日志命令 tail
- linux查看日志文件内容命令tail、cat、tac、head、echo详解
- Linux查看日志 tail cat sed 等命令
- linux查看日志文件内容命令tail、cat、tac、head、echo
- (转)linux查看日志文件内容命令tail、cat、tac、head、echo
- 菜鸟学Linux命令:tail命令 查看日志
- linux查看日志文件内容命令tail、cat、tac、head、echo
- 【Linux】linux查看日志文件内容命令tail、cat、tac、head、echo
- Linux查看文件最后几行的命令,日志的福音啊
- 使用tail命令实时查看日志文件
- linux tail命令的使用方法详解 和 Linux 服务器查看日志基本命令