Linux head/tail命令详解程序员
2023-06-13 09:20:05 时间
head命令用于显示文件的开头的内容。在默认情况下,head命令显示文件的头10行内容。
tail命令用于显示文件的结尾的内容。在默认情况下,taild命令显示文件的后10行内容。
head常见命令参数-c, --bytes=[-]K print the first K bytes of each file; with the leading `-, print all but the last K bytes of each file -n, --lines=[-]K print the first K lines instead of the first 10; with the leading `-, print all but the last K lines of each file -q, --quiet, --silent never print headers giving file names -v, --verbose always print headers giving file names --help display this help and exit --version output version information and exittail场景命令
-c, --bytes=K output the last K bytes; alternatively, use -c +K to output bytes starting with the Kth of each file -f, --follow[={name|descriptor}] output appended data as the file grows; -f, --follow, and --follow=descriptor are equivalent -F same as --follow=name --retry -n, --lines=K output the last K lines, instead of the last 10; or use -n +K to output lines starting with the Kth --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 with -f, terminate after process ID, PID dies -q, --quiet, --silent never output headers giving file names --retry keep trying to open a file even when it is or becomes inaccessible; useful when following by name, i.e., with --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. -v, --verbose always output headers giving file names --help display this help and exit --version output version information and exit常用的命令展示
head :显示文件的前几行,默认10行 head -n 2 /home/omd/h.txt == head -n 3 == head -3 可以直接跟行数 cat h.txt | grep -v "hello" 过滤掉特定字符串,效率低,因为有管道 == grep -v "hello" h.txt 可以直接跟文件名,效率快 tail: 显示文件最后几行,默认10行 tail -10 /home/omd/h.txt 显示最后10行 tail -f /home/omd/h.txt 实时跟踪文件, 如果文件不存在,则终止 tail -F /home/omd/h.txt 如果文件不存在,会继续尝试 head -30 /home/omd/h.txt | tail -11 /home/omd/h.txt 输出一个文件的20-30行显示文件的前n行 head -n 5 log2014.log输出文件除了最后n行的全部内容 head -n -6 log2014.log从第5行开始显示文件 tail -n +5 log2014.log 【显示文件的全部内容】 tail -n 5 log2014.log 【只显示最后的5行】 根more/less差不多
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/2988.html
服务器部署程序员系统优化网站设置运维相关文章
- linux route add 接口,route add命令如何使用「建议收藏」
- Linux 运行jar包命令[通俗易懂]
- linux中echo命令的使用详解程序员
- Linux 下压缩打包命令实用指南(linux压缩打包命令)
- Linux命令:安装新程序的快捷方式(linux命令安装程序)
- Linux 中查看线程的技巧与方法(linux查看线程)
- 简单快速:在Linux系统下使用FTP工具(linux下ftp工具)
- 快速查看 Linux 命令历史记录(linux查看命令历史)
- Linux中的 .命令深度探索(linux中.)
- 使用情况国内 Linux 空间:发展与启示(国内linux空间)
- Linux帮助修复Win7系统(linux修复win7)
- Linux下日期操纵之date命令(linux下date命令)
- Linux的多元发展:开源系统的新分支(linux的分支)
- 及其作用深入了解Linux的分支及其作用(linux的分支)
- Linux的发展:从单一核心到多核心(linux的分支)
- jaro快速安装 Manjaro 带来的 Linux 乐趣(linux安装man)
- 掌握Linux的神器——At命令(at命令linux)
- Linux 中Top命令的作用(linux命令top)
- Linux命令大全:一款强大的学习工具(linux命令大全软件)
- Linux下的电路仿真技术(linux电路仿真)
- Linux下如何配置DHCP服务器(linux配置dhcp服务器)
- Linux自动同步时间:简单命令即可完成(linux自动同步时间命令)
- 提升 Linux 性能的 5 个实用命令(linux性能命令)
- Linux下的进入目录技巧:以命令行方式操作(linux命令进入目录)
- Linux下安装KATE文本编辑器的指南(linux安装kate)
- 使用bc命令实现高精度计算——深入探索Linux中的bc(linux中bc)
- 25个Linux软件管理命令,我学会了!(linux软件管理命令)
- 轻松学习:如何使用Linux命令查看网页?(linux命令查看网页)
- Linux命令:立即生效?(linux立即生效吗)
- “割掉”文件 Linux中cut命令(cut命令linux)
- Linux命令大全:如何使用命令查看文件内容?(linux显示文件内容命令)
- Linux系统如何删除与恢复文件(linux 删除 恢复)
- 编程Linux嵌入式C语言编程实践(linux 嵌入式c)