Bash 的 tail 命令

作者:hubenchang0515日期:2025/11/16

#Bash 的 tail 命令

1tail [OPTION]... [FILE]...
2

功能

查看文件的末尾。

类型

可执行文件(/usr/bin/tail),属于 coreutils

参数

  • OPTION 选项:
    • -c, --bytes=[+]NUM - 查看文件末尾的 NUM 字节,如果使用正号,则表示查看第 NUM 字节之后的内容
    • -f, --follow[={name|descriptor}] - 跟随文件,当文件内容增加时打印追加的内容
    • -F - 等价于 --follow=name --retry
    • -n, --lines=[+]NUM - 查看文件末尾的 NUM 行,如果使用正号,则表示查看第 NUM 行之后的内容
    • --max-unchanged-stats=N - 使用 -f 选项选项时,如果连续 N 次读取文件不变,则尝试重新打开文件
    • --pid=PID - 使用 -f 选项选项时,当 PID 进程结束时停止此命令
    • -q, --quiet, --silent - 不打印包含文件名在内的头部信息
    • --retry - 如果文件无法打开,则重新尝试打开
    • -v, --verbose - 打印包含文件名在内的头部信息
    • -z, --zero-terminated - 以空字符(\0)作为行的结尾,而不是换行符(\n
    • --help - 显示帮助
    • --version - 显示版本
  • FILE - 文件列表,如果没有这个参数或指定为 -,则读取标准输入

#示例

基本功能

1$ man tail | tail -n 5                  # 查看末尾 5 行
2
3       Full documentation <https://www.gnu.org/software/coreutils/tail>
4       or available locally via: info '(coreutils) tail invocation'
5
6GNU coreutils 9.4                 April 2024                           TAIL(1)
7$ man tail | tail -n +90                # 显示第 90 行之后的内容
8       There is NO WARRANTY, to the extent permitted by law.
9
10SEE ALSO
11       head(1)
12
13       Full documentation <https://www.gnu.org/software/coreutils/tail>
14       or available locally via: info '(coreutils) tail invocation'
15
16GNU coreutils 9.4                 April 2024                           TAIL(1)
17

监听日志

1$ tail -f /var/log/syslog       # 监听该文件,文件内容更新时打印追加的内容
22025-11-15T08:30:00.190259+00:00 dev systemd[1]: Finished sysstat-collect.service - system activity accounting tool.
32025-11-15T08:35:01.817178+00:00 dev CRON[3239701]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
42025-11-15T08:40:00.422316+00:00 dev systemd[1]: Starting sysstat-collect.service - system activity accounting tool...
52025-11-15T08:40:00.435212+00:00 dev systemd[1]: sysstat-collect.service: Deactivated successfully.
62025-11-15T08:40:00.435761+00:00 dev systemd[1]: Finished sysstat-collect.service - system activity accounting tool.
72025-11-15T08:45:01.832707+00:00 dev CRON[3241555]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
82025-11-15T08:50:00.422442+00:00 dev systemd[1]: Starting sysstat-collect.service - system activity accounting tool...
92025-11-15T08:50:00.434650+00:00 dev systemd[1]: sysstat-collect.service: Deactivated successfully.
102025-11-15T08:50:00.435219+00:00 dev systemd[1]: Finished sysstat-collect.service - system activity accounting tool.
112025-11-15T08:55:01.848254+00:00 dev CRON[3243092]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
12
13

#相关命令

命令说明
head查看文件开头
more分页查看文件内容
less增强版文件分页阅读命令

#推荐阅读

#手册

显示

1TAIL(1)                          User Commands                         TAIL(1)
2
3NAME
4       tail - output the last part of files
5
6SYNOPSIS
7       tail [OPTION]... [FILE]...
8
9DESCRIPTION
10       Print  the  last  10  lines of each FILE to standard output.  With more
11       than one FILE, precede each with a header giving the file name.
12
13       With no FILE, or when FILE is -, read standard input.
14
15       Mandatory arguments to long options are  mandatory  for  short  options
16       too.
17
18       -c, --bytes=[+]NUM
19              output  the  last  NUM  bytes; or use -c +NUM to output starting
20              with byte NUM of each file
21
22       -f, --follow[={name|descriptor}]
23              output appended data as the file grows;
24
25              an absent option argument means 'descriptor'
26
27       -F     same as --follow=name --retry
28
29       -n, --lines=[+]NUM
30              output the last NUM lines, instead of the last  10;  or  use  -n
31              +NUM to skip NUM-1 lines at the start
32
33       --max-unchanged-stats=N
34              with --follow=name, reopen a FILE which has not
35
36              changed  size  after  N  (default 5) iterations to see if it has
37              been unlinked or renamed (this is the usual case of rotated  log
38              files); with inotify, this option is rarely useful
39
40       --pid=PID
41              with -f, terminate after process ID, PID dies
42
43       -q, --quiet, --silent
44              never output headers giving file names
45
46       --retry
47              keep trying to open a file if it is inaccessible
48
49       -s, --sleep-interval=N
50              with -f, sleep for approximately N seconds (default 1.0) between
51              iterations;  with  inotify and --pid=P, check process P at least
52              once every N seconds
53
54       -v, --verbose
55              always output headers giving file names
56
57       -z, --zero-terminated
58              line delimiter is NUL, not newline
59
60       --help display this help and exit
61
62       --version
63              output version information and exit
64
65       NUM may have a multiplier suffix: b 512, kB 1000, K 1024, MB 1000*1000,
66       M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and so on for  T,  P,
67       E,  Z, Y, R, Q.  Binary prefixes can be used, too: KiB=K, MiB=M, and so
68       on.
69
70       With --follow (-f), tail defaults to  following  the  file  descriptor,
71       which  means that even if a tail'ed file is renamed, tail will continue
72       to track its end.  This default behavior is not desirable when you  re‐
73       ally want to track the actual name of the file, not the file descriptor
74       (e.g.,  log  rotation).   Use  --follow=name in that case.  That causes
75       tail to track the named file in a way that accommodates  renaming,  re‐
76       moval and creation.
77
78AUTHOR
79       Written  by Paul Rubin, David MacKenzie, Ian Lance Taylor, and Jim Mey‐
80       ering.
81
82REPORTING BUGS
83       GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
84       Report any translation bugs to <https://translationproject.org/team/>
85
86COPYRIGHT
87       Copyright © 2023 Free Software Foundation, Inc.   License  GPLv3+:  GNU
88       GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
89       This  is  free  software:  you  are free to change and redistribute it.
90       There is NO WARRANTY, to the extent permitted by law.
91
92SEE ALSO
93       head(1)
94
95       Full documentation <https://www.gnu.org/software/coreutils/tail>
96       or available locally via: info '(coreutils) tail invocation'
97
98GNU coreutils 9.4                 April 2024                           TAIL(1)
99

Bash 的 tail 命令》 是转载文章,点击查看原文


相关推荐


Python 的内置函数 max
IMPYLH2025/11/15

Python 内建函数列表 > Python 的内置函数 max Python 的内置函数 max() 是一个用于返回可迭代对象中最大元素或多个参数中最大值的实用函数。它支持多种数据类型和灵活的调用方式,是 Python 编程中常用的工具之一。 基本用法 单个可迭代对象: numbers = [3, 1, 4, 1, 5, 9, 2] print(max(numbers)) # 输出:9 多个参数: print(max(3, 1, 4, 1, 5)) # 输出:5 关键参数


IM 收件箱机制(三)
锅拌饭2025/11/14

在IM中,有了长连接之后,如何完成服务端与客户端的数据同步也是很重要的一环。 通常会有两种方案,一个是服务端直接转发,一个是收件箱机制。我们以消息类型的数据为例。 服务端直接转发: 是服务端收到消息A,存储完成后,直接将消息A的具体内容通过长连接通道发送给客户端B。我们把这种方式叫做服务端直接转发。 收件箱: 服务端收到消息后,不直接转发该消息给客户端,而是将消息id、消息所在会话id推送给客户端的消息收件箱,客户端发现消息收件箱有数据后,择机通过长连接 or 短连接拉取消息具体内容。 服务端直


C#.NET WebAPI 返回类型深度解析:IActionResult 与 ActionResult<T> 的区别与应用
唐青枫2025/11/13

简介 核心概念对比 特性IActionResultActionResult<T>引入版本ASP.NET Core 1.0ASP.NET Core 2.1主要用途表示HTTP响应(状态码+内容)类型化HTTP响应返回值类型接口(多种实现)泛型类内容类型安全❌ 无编译时检查✅ 编译时类型检查OpenAPI/Swagger需手动添加 [ProducesResponseType]自动推断响应类型适用场景需要灵活返回多种响应的


Python 的内置函数 help
IMPYLH2025/11/11

Python 内建函数列表 > Python 的内置函数 help Python 的内置函数 help 详解 基本功能 help() 是 Python 的一个内置函数,主要用于查看对象、模块、函数、类等的帮助文档。这个功能对于了解 Python 的各种组件及其使用方法非常有用,特别是在开发过程中需要快速查看某个功能的用法时。 使用方法 直接调用 help() help() 启动交互式帮助系统,此时可以输入模块名、函数名等查看帮助信息,输入"quit"退出帮助系统。 查看特定对象的


Vue SSR 源码解析:ssrTransformSuspense 与 ssrProcessSuspense
excel2025/11/9

一、背景与概念说明 Vue 在服务端渲染(SSR)过程中,会对组件模板进行两阶段编译: 阶段一(Transform) :生成用于描述结构的中间表达(IR, Intermediate Representation)。 阶段二(Codegen) :将中间表达转换为最终的字符串拼接指令(例如 _push、_renderSlot)。 而 <Suspense> 组件是 Vue 3 的一个特殊机制,用于异步内容加载与占位渲染。 在 SSR 环境下,Vue 需要为 <Suspense> 生成可在服务端正确


C++中的多态:动态多态与静态多态详解
oioihoii2025/11/6

多态是面向对象编程的三大特性之一,C++提供了两种主要的多态形式:动态多态和静态多态。本文将详细解释它们的区别,并通过代码示例进行说明。 什么是多态? 多态(Polymorphism)指同一个接口可以表现出不同的行为。在C++中,这允许我们使用统一的接口来处理不同类型的对象。 动态多态(运行时多态) 动态多态在程序运行时确定调用哪个函数,主要通过虚函数和继承机制实现。 实现机制 使用虚函数(virtual function) 通过继承关系 运行时通过虚函数表(vtable)决定调用哪个函数


图的寻路算法详解:基于深度优先搜索(DFS)的实现
Seal^_^2025/11/2

图的寻路算法详解:基于深度优先搜索DFS的实现 一、寻路算法概述DFS寻路示例 二、算法核心思想数据结构设计 三、算法实现详解1. 核心数据结构2. 构造函数初始化3. DFS实现4. 路径查询方法 四、完整代码实现五、算法测试与应用测试代码输出结果 六、算法分析与优化时间复杂度分析空间复杂度优化方向 七、DFS寻路与BFS寻路对比八、实际应用场景九、总结 🌺The Begin🌺点点关注,收藏不迷路🌺


高并发压力测试:Llama-2-7b 在昇腾 NPU 的六大场景表现
2501_938774292025/10/30

以下是关于 Llama-2-7b 在昇腾 NPU 上进行高并发压力测试的六大场景表现分析,结合网络公开信息和技术逻辑整理而成: 场景一:文本生成吞吐量测试 在批量文本生成任务中(如问答、摘要),昇腾 NPU 通过异构计算架构优化模型并行度。实测数据显示,当并发请求数从 100 提升至 1000 时,吞吐量增长约 3.8 倍,但单请求响应时间增加 15%-20%,显存占用峰值达 80%。 关键指标: 吞吐量:1200 tokens/s(batch_size=32)延迟:50ms/toke


Swift 官方发布 Android SDK | 肘子的 Swift 周报 #0108
东坡肘子2025/10/28

📮 想持续关注 Swift 技术前沿? 每周一期《肘子的 Swift 周报》,为你精选本周最值得关注的 Swift、SwiftUI 技术文章、开源项目和社区动态。 📬 在 weekly.fatbobman.com 免费订阅 💬 加入 Discord 与中文 Swift 开发者深入交流 📚 访问 fatbobman.com 查看数百篇深度原创教程  一起构建更好的 Swift 应用!🚀 Swift 官方发布 Android SDK 10 月 24 日,Swift Android 工


大模型时代的广告营销变革与实践
京东零售技术2025/10/25

大模型时代的广告营销变革与实践 互联网领域,广告营销是一种核心业态,也是先进技术和研究成果的商业化进程最快的一种渠道。伴随生成式大模型的浪潮汹涌袭来,京东广告结合自身业务特性和电商零售的新业态,推出了自主研发的广告营销商业化场景大模型,并据此带来了一场深刻的技术和业务变革。 在2025年9月25日,京东JDD(京东全球科技探索者)大会的Oxygen 智能零售论坛上,京东广告团队做了题为《大模型时代的广告营销变革与实践》的报告。 核心观点 1. 通用大模型想解决营销领域问题需向垂类模型转型。 “全

首页编辑器站点地图

Copyright © 2025 聚合阅读

License: CC BY-SA 4.0