天天看点

linux基础命令之tail

tail 命令可用于查看文件的内容,有一个常用的参数 -f 常用于查阅正在改变的日志文件。

tail -f filename 会把 filename 文件里的最尾部的内容显示在屏幕上,并且不断刷新,只要 filename 更新就可以看到最新的文件内容。

用法:tail [选项]... [文件]...

显示每个指定文件的最后 10 行并输出至标准输出。

若指定了多于一个文件,程序会在每段输出的开始添加相应文件名作为头。

如果没有指定文件,或者文件为"-",则从标准输入读取。

必选参数对长短选项同时适用。

  -c, --bytes=[+]NUM       输出最后 NUM 字节;或者使用 -c +NUM 以输出

                             每个文件第 NUM 个字节之后的全部内容

  -f, --follow[={name|descriptor}]

                           随文件增长即时输出新增数据;

                             若未给定选项参数,则默认使用 'descriptor'

  -F                       和 --follow=name --retry 相同

  -n, --lines=[+]NUM       output the last NUM lines, instead of the last 10;

                             or use -n +NUM to output starting with line NUM

      --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

      --pid=PID            同 -f 一起使用,当所指定<PID>对应的进程死去后终止

  -q, --quiet, --silent    不输出给出文件名的头

      --retry              即使目标文件不可访问依然重复试图打开

  -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

  -v, --verbose            always output headers giving file names

  -z, --zero-terminated    以 NUL 字符而非换行符作为行尾分隔符

      --help        显示此帮助信息并退出

      --version        显示版本信息并退出

要跟踪名为 notes.log 的文件的增长情况,请输入以下命令:

tail -f notes.log