• tail命令应用


    记录:347

    场景:在CentOS 7.9操作系统上,使用tail命令指定行数查看文件内容;使用tail查看文件实时输出内容。比如查看Tomcat的日志文件等。

    版本:

    操作系统:CentOS 7.9

    1.命令应用

    在/home/apps/work目录下,有文件intro.txt。

    (1)指定行数查看内容

    命令:tail -n 10 intro.txt

    解析:tail -n 10,输出文件的最后10行内容。

    (2)查看文件实时输出内容

    命令:tail -f intro.txt

    命令:tail -F intro.txt

    解析:tail -f ,查看文件实时输出内容,比如查看Tomcat的catalina.out时,只要服务在运行,就可以实时打印服务运行日志。

    (3)查看最近几秒的文件内容

    命令:tail -s 10 intro.txt

    解析:查看最近几秒的文件内容

    (4)查看版本

    命令:tail --version

    解析:查看版本信息,本例:tail (GNU coreutils) 8.22。

    (5)输出指定字节的内容

    命令:tail -c 1024 intro.txt

    解析:输出文件最后1024字节内容。

    2.命令帮助手册

    命令:tail --help

    解析:查看tail支持全部命令和选项,在实际工作中,查看这个手册应该是必备之选。

    1. Usage: tail [OPTION]... [FILE]...
    2. Print the last 10 lines of each FILE to standard output.
    3. With more than one FILE, precede each with a header giving the file name.
    4. With no FILE, or when FILE is -, read standard input.
    5. Mandatory arguments to long options are mandatory for short options too.
    6. -c, --bytes=K output the last K bytes; or use -c +K to output
    7. bytes starting with the Kth of each file
    8. -f, --follow[={name|descriptor}]
    9. output appended data as the file grows;
    10. an absent option argument means 'descriptor'
    11. -F same as --follow=name --retry
    12. -n, --lines=K output the last K lines, instead of the last 10;
    13. or use -n +K to output starting with the Kth
    14. --max-unchanged-stats=N
    15. with --follow=name, reopen a FILE which has not
    16. changed size after N (default 5) iterations
    17. to see if it has been unlinked or renamed
    18. (this is the usual case of rotated log files);
    19. with inotify, this option is rarely useful
    20. --pid=PID with -f, terminate after process ID, PID dies
    21. -q, --quiet, --silent never output headers giving file names
    22. --retry keep trying to open a file if it is inaccessible
    23. -s, --sleep-interval=N with -f, sleep for approximately N seconds
    24. (default 1.0) between iterations;
    25. with inotify and --pid=P, check process P at
    26. least once every N seconds
    27. -v, --verbose always output headers giving file names
    28. --help display this help and exit
    29. --version output version information and exit
    30. If the first character of K (the number of bytes or lines) is a '+',
    31. print beginning with the Kth item from the start of each file, otherwise,
    32. print the last K items in the file. K may have a multiplier suffix:
    33. b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
    34. GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.
    35. With --follow (-f), tail defaults to following the file descriptor, which
    36. means that even if a tail'ed file is renamed, tail will continue to track
    37. its end. This default behavior is not desirable when you really want to
    38. track the actual name of the file, not the file descriptor (e.g., log
    39. rotation). Use --follow=name in that case. That causes tail to track the
    40. named file in a way that accommodates renaming, removal and creation.
    41. GNU coreutils online help:
    42. For complete documentation, run: info coreutils 'tail invocation'

    以上,感谢。

    2022年11月27日

  • 相关阅读:
    Java 中经常被提到的 SPI 到底是什么?
    webpack5 eslint插件使用
    网页设计大作业模板-网页设计大作业(文房四宝 5页)-实训素材
    aggregate和annotate方法使用
    docker安装常用软件
    PackML 学习笔记(2) OPCUA /PackML
    设计模式之职责链模式应用例题
    django configparser.NoSectionError: No section: ‘Samples
    技术分享 | 使用 Zabbix + Grafana 搭建服务器监控系统
    第二章 编译运行Android Wenet语音识别
  • 原文地址:https://blog.csdn.net/zhangbeizhen18/article/details/128071950