Linux 终端命令之文件浏览(4) head, tail

news2024/11/25 6:51:05

18647a9c4d804f0eacedc1984bee2940.png

Linux 文件浏览命令

cat, more, less, head, tail,此五个文件浏览类的命令皆为外部命令。

hann@HannYang:~$ which cat
/usr/bin/cat
hann@HannYang:~$ which more
/usr/bin/more
hann@HannYang:~$ which less
/usr/bin/less
hann@HannYang:~$ which head
/usr/bin/head
hann@HannYang:~$ which tail
/usr/bin/tail

(4) head

英文帮助

NAME
       head - output the first part of files

SYNOPSIS
       head [OPTION]... [FILE]...

DESCRIPTION
       Print the first 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.

       Mandatory arguments to long options are mandatory for short options too.

       -c, --bytes=[-]NUM
              print the first NUM bytes of each file; with the leading '-', print all but the last NUM bytes of each file

       -n, --lines=[-]NUM
              print the first NUM lines instead of the first 10; with the leading '-', print all but the last NUM lines of each file

       -q, --quiet, --silent
              never print headers giving file names

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

       -z, --zero-terminated
              line delimiter is NUL, not newline

       --help display this help and exit

       --version
              output version information and exit

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

AUTHOR
       Written by David MacKenzie and Jim Meyering.

REPORTING BUGS
       GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
       Report head translation bugs to <https://translationproject.org/team/>

COPYRIGHT
       Copyright © 2018 Free Software Foundation, Inc.  License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
       This is free software: you are free to change and redistribute it.  There is NO WARRANTY, to the extent permitted by law.

SEE ALSO
       tail(1)

       Full documentation at: <https://www.gnu.org/software/coreutils/head>
       or available locally via: info '(coreutils) head invocation'

中文注释

head [参数] 文件名——显示文件的前几行

参数选项:
 -n num:显示文件的前num行。
 -c num:显示文件的前num字节的字符,num可以使用K,KB,M,MB等数量单位。
缺省时,head显示文件的前10行。

-v / -q : 首行是否显示文件名。
-z :行分隔符为NUL。一般地,head -z myfile 就等效 cat myfile。

示例:

hann@HannYang:~$ head -n 6 cmds.txt
alias - Define or display aliases.
alias: alias [-p] [name[=value] ... ]
bg - Move jobs to the background.
bg: bg [job_spec ...]
bind - Set Readline key bindings and variables.
bind: bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
hann@HannYang:~$ head cmds.txt
alias - Define or display aliases.
alias: alias [-p] [name[=value] ... ]
bg - Move jobs to the background.
bg: bg [job_spec ...]
bind - Set Readline key bindings and variables.
bind: bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
break - Exit for, while, or until loops.
break: break [n]
builtin - Execute shell builtins.
builtin: builtin [shell-builtin [arg ...]]
hann@HannYang:~$ head -c 35 cmds.txt
alias - Define or display aliases.
hann@HannYang:~$ head -c 50 cmds.txt
alias - Define or display aliases.
alias: alias [-hann@HannYang:~$ head -c 1K cmds.txt
alias - Define or display aliases.
alias: alias [-p] [name[=value] ... ]
bg - Move jobs to the background.
bg: bg [job_spec ...]
bind - Set Readline key bindings and variables.
bind: bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
break - Exit for, while, or until loops.
break: break [n]
builtin - Execute shell builtins.
builtin: builtin [shell-builtin [arg ...]]
caller - Return the context of the current subroutine call.
caller: caller [expr]
case - Execute commands based on pattern matching.
case: case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac
cd - Change the shell working directory.
cd: cd [-L|[-P [-e]] [-@]] [dir]
command - Execute a simple command or display information about commands.
command: command [-pVv] command [arg ...]
compgen - Display possible completions depending on the options.
compgen: compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C cohann@HannYang:~$ head -c 1KB cmds.txt
alias - Define or display aliases.
alias: alias [-p] [name[=value] ... ]
bg - Move jobs to the background.
bg: bg [job_spec ...]
bind - Set Readline key bindings and variables.
bind: bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
break - Exit for, while, or until loops.
break: break [n]
builtin - Execute shell builtins.
builtin: builtin [shell-builtin [arg ...]]
caller - Return the context of the current subroutine call.
caller: caller [expr]
case - Execute commands based on pattern matching.
case: case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac
cd - Change the shell working directory.
cd: cd [-L|[-P [-e]] [-@]] [dir]
command - Execute a simple command or display information about commands.
command: command [-pVv] command [arg ...]
compgen - Display possible completions depending on the options.
compgen: compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlishann@HannYang:~$ head -v cmds.txt
==> cmds.txt <==
alias - Define or display aliases.
alias: alias [-p] [name[=value] ... ]
bg - Move jobs to the background.
bg: bg [job_spec ...]
bind - Set Readline key bindings and variables.
bind: bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
break - Exit for, while, or until loops.
break: break [n]
builtin - Execute shell builtins.
builtin: builtin [shell-builtin [arg ...]]

注意区别:

-c 35  和 -c 50 的区别,前者刚好有换行符结尾。

-c 1K 和 -c 1KB 的区别,前者1024后者1000;M和MB,G和GB的区别同理。

--help 简要帮助

hann@HannYang:~$ head --help
Usage: head [OPTION]... [FILE]...
Print the first 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.

Mandatory arguments to long options are mandatory for short options too.
  -c, --bytes=[-]NUM       print the first NUM bytes of each file;
                             with the leading '-', print all but the last
                             NUM bytes of each file
  -n, --lines=[-]NUM       print the first NUM lines instead of the first 10;
                             with the leading '-', print all but the last
                             NUM lines of each file
  -q, --quiet, --silent    never print headers giving file names
  -v, --verbose            always print headers giving file names
  -z, --zero-terminated    line delimiter is NUL, not newline
      --help     display this help and exit
      --version  output version information and exit

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

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report head translation bugs to <https://translationproject.org/team/>
Full documentation at: <https://www.gnu.org/software/coreutils/head>
or available locally via: info '(coreutils) head invocation'

--version 版本号

hann@HannYang:~$ head --version
head (GNU coreutils) 8.30
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David MacKenzie and Jim Meyering.

(5) tail

英文帮助

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.

       Mandatory arguments to long options are mandatory for short options too.

       -c, --bytes=[+]NUM
              output the last NUM bytes; or use -c +NUM to output starting with byte NUM of each file

       -f, --follow[={name|descriptor}]
              output appended data as the file grows;

              an absent option argument means 'descriptor'

       -F     same as --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
              with -f, terminate after process ID, PID dies

       -q, --quiet, --silent
              never output headers giving file names

       --retry
              keep trying to open a file if it is inaccessible

       -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
              line delimiter is NUL, not newline

       --help display this help and exit

       --version
              output version information and exit

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

       With  --follow  (-f),  tail defaults to following the file descriptor, which means that even if a tail'ed file is renamed, tail will continue to track its end.  This default behavior is not desirable when you really want to track the actual name of the file, not the file descriptor (e.g., log rotation).  Use --follow=name in that case.  That causes tail to track the named file in a way that accommodates renaming, removal and creation.

AUTHOR
       Written by Paul Rubin, David MacKenzie, Ian Lance Taylor, and Jim Meyering.

REPORTING BUGS
       GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
       Report tail translation bugs to <https://translationproject.org/team/>

COPYRIGHT
       Copyright © 2018 Free Software Foundation, Inc.  License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
       This is free software: you are free to change and redistribute it.  There is NO WARRANTY, to the extent permitted by law.

SEE ALSO
       head(1)

       Full documentation at: <https://www.gnu.org/software/coreutils/tail>
       or available locally via: info '(coreutils) tail invocation'

中文注释

tail [参数] 文件名——显示文件的末尾几行
参数选项:
 -n num:显示文件的末尾num行。
 -c num:显示文件的末尾num字节的字符。
tail命令和head命令相反,它显示文件的末尾。
缺省时,tail命令显示文件的末尾10行

这两个参数与head基本相同,还有-q -v -z也一样。

tail命令另外还多了几个参数: -f -s --pid --retry等。

-f:该参数用于实时监控文件并输出最新的内容。例如,tail -f -n 10 /var/log/syslog表示实时监控/var/log/syslog文件的最后10行内容,并输出最新的内容。
-s或--sleep-interval:这个参数用于指定每次输出文件内容之间的休眠时间。例如,tail -f -s 2表示在每次输出文件内容之间休眠2秒。
--pid:该参数用于指定要监控的进程号(PID)。例如,tail -f --pid 12345表示监控进程号12345的进程。
--retry:该参数用于在监控的进程重新启动后继续监控。例如,tail -f --pid 12345 --retry表示在进程重新启动后继续监控。

 --help 简要帮助

Usage: tail [OPTION]... [FILE]...
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.

Mandatory arguments to long options are mandatory for short options too.
  -c, --bytes=[+]NUM       output the last NUM bytes; or use -c +NUM to
                             output starting with byte NUM of each file
  -f, --follow[={name|descriptor}]
                           output appended data as the file grows;
                             an absent option argument means 'descriptor'
  -F                       same as --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            with -f, terminate after process ID, PID dies
  -q, --quiet, --silent    never output headers giving file names
      --retry              keep trying to open a file if it is inaccessible
  -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    line delimiter is NUL, not newline
      --help     display this help and exit
      --version  output version information and exit

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

With --follow (-f), tail defaults to following the file descriptor, which
means that even if a tail'ed file is renamed, tail will continue to track
its end.  This default behavior is not desirable when you really want to
track the actual name of the file, not the file descriptor (e.g., log
rotation).  Use --follow=name in that case.  That causes tail to track the
named file in a way that accommodates renaming, removal and creation.

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report tail translation bugs to <https://translationproject.org/team/>
Full documentation at: <https://www.gnu.org/software/coreutils/tail>
or available locally via: info '(coreutils) tail invocation'

--version 版本号

hann@HannYang:~$ tail --version
tail (GNU coreutils) 8.30
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Paul Rubin, David MacKenzie, Ian Lance Taylor,
and Jim Meyering.

相关阅读:

Linux 终端命令之文件浏览(1) cat_Hann Yang的博客-CSDN博客

Linux 终端命令之文件浏览(2) more_Hann Yang的博客-CSDN博客

Linux 终端命令之文件浏览(3) less_Hann Yang的博客-CSDN博客

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/873223.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

流量日志分析--实操

[鹤城杯 2021]流量分析 <--第一道流量分析不难,主要就是布尔盲注的流量包分析,直接查看http请求包即可我们可以通过观察看到注入成功的响应长度不同,这里成功的为978字节,失败的994字节.不要问为什么.其实也可以直接判断.978的流量比994的少了非常多 显然就是成功的(因为这里…

云计算|OpenStack|使用VMware安装华为云的R006版CNA和VRM---初步使用(二)

前言&#xff1a; 在前面一篇文章云计算|OpenStack|使用VMware安装华为云的R006版CNA和VRM---初始安装&#xff08;一&#xff09;_华为cna_晚风_END的博客-CSDN博客 介绍了基于VMware虚拟机里嵌套部署华为云的云计算&#xff0c;不过仅仅是做到了在VRM的web界面添加计算节点…

高效数据传输:轻松上手将Kafka实时数据接入CnosDB

本篇我们将主要介绍如何在 Ubuntu 22.04.2 LTS 环境下&#xff0c;实现一个KafkaTelegrafCnosDB 同步实时获取流数据并存储的方案。在本次操作中&#xff0c;CnosDB 版本是2.3.0&#xff0c;Kafka 版本是2.5.1&#xff0c;Telegraf 版本是1.27.1 随着越来越多的应用程序架构转…

keil构建STM32工程并使用proteus仿真led点灯实验

STM32单片机与51单片机有很大区别&#xff0c;不仅结构上有很大差异&#xff0c;STM32更复杂一些&#xff0c;在操作上来说&#xff0c;STM32也要复杂很多&#xff0c;51单片机上手写代码&#xff0c;可以很直接操作引脚&#xff0c;但是STM32单片机在操作引脚之前需要作很多初…

学无止境·运维高阶⑤(LVS-DR 群集 配置Nginx负载均衡)

LVS-DR 群集 && 配置Nginx负载均衡 一、LVS-DR 群集1、相关配置环境2、在RS上配置并启动脚本2.1相关脚本2.2 启动脚本&#xff0c;另一台RS同样步骤 3、LVS-DR模式配置脚本4、测试 二、Nginx负载均衡1、安装Nginx并关闭相应设置2、向主机 node2&#xff0c;node3 写入内…

【第二阶段】kotlin函数引用

针对上篇传入函数参数我们也可以重新定义一个函数&#xff0c;然后在main中调用时传入函数对象 lambda属于函数类型的对象&#xff0c;需要把普通函数变成函数类型的对象&#xff08;函数引用&#xff09;&#xff0c;使用“&#xff1a;&#xff1a;” /*** You can edit, ru…

[足式机器人]Part3机构运动微分几何学分析与综合Ch03-1 空间约束曲线与约束曲面微分几何学——【读书笔记】

本文仅供学习使用 本文参考&#xff1a; 《机构运动微分几何学分析与综合》-王德伦、汪伟 《微分几何》吴大任 Ch01-4 平面运动微分几何学 3.1 空间曲线微分几何学概述3.1.1 矢量表示3.1.2 Frenet标架 连杆机构中的连杆与连架杆构成运动副&#xff0c;该运动副元素的特征点或特…

二十二、策略模式

目录 1、项目需求2、传统方案解决鸭子问题的分析和代码实现3、传统方式实现存在的问题分析和解决方案4、策略模式基本介绍5、使用策略模式解决鸭子问题6、策略模式的注意事项和细节7、策略模式的使用场景 以具体项目来演示为什么需要策略模式&#xff0c;策略模式的优点&#x…

GitHub 如何部署写好的H5静态页面

感谢粉皮zu的私信&#xff0c;又有素材写笔记了。(●’◡’●) 刚好记录一下我示例代码的GitHub部署配置&#xff0c;以便于后期追加仓库。 效果 环境 gitwin 步骤 第一步 新建仓库 第二步 拉取代码 将仓库clone到本地 git clone 地址第三步 部署文件 新建.github\workflo…

线性规划模型-应用篇

文章目录 模型特点使用技巧工具包和求解器模型线性化 应用实例经验总结 模型特点 上一篇中&#xff0c;详细阐述了线性规划问题和单纯形法的算法原理&#xff0c;本文将着重介绍线性模型在工业场景中的应用。 首先需要说清楚的是&#xff0c;为什么线性模型深受研发人员青睐。…

五、约束编程求解优化问题

文章目录 1、瑶草问题-离散优化问题2、重试优化3、分支限界法-改进重试优化法4、重启式搜索4.1 重启方针/策略4.2 自动化搜索策略 THE END 1、瑶草问题-离散优化问题 \qquad 要求在一个建木上构建一个完整的分枝树&#xff0c;每一个完整的分枝有100段&#xff0c;完整分枝上的…

2023年《开学第一课》播出时间是什么时候?开学第一课怎么在手机上观看高清直播?

2023年《开学第一课》播出时间是什么时候&#xff1f; 根据往年《开学第一课》播出时间预计2023年《开学第一课》播出时间是2023年9月1日20:00&#xff0c;如有变化请以官方公布为准&#xff1b; 2023年开学第一课怎么在手机上观看高清直播&#xff1f; 1、打开手机微信&…

第三章,矩阵,07-用初等变换求逆矩阵、矩阵的LU分解

第三章&#xff0c;矩阵&#xff0c;07-用初等变换求逆矩阵、矩阵的LU分解 一个基本的方法求 A − 1 B A^{-1}B A−1BLU分解例1&#xff0c;求矩阵A的LU分解&#xff1a;例12&#xff0c;LU分解解线性方程组&#xff1a; 玩转线性代数(19)初等矩阵与初等变换的相关应用的笔记&a…

Rx.NET in Action 第一章学习笔记

Part 1 初入反应式扩展 什么是反应式程序&#xff1f;它们有什么用&#xff1f;使用反应式扩展&#xff08;Rx&#xff09;编程&#xff0c;会如何改变你编写代码的方式&#xff1f;在开始使用 Rx 之前应该做些什么&#xff1f;为什么 Rx 比传统的事件驱动编程更好&#xff1f…

简单认识Zabbix监控系统及配置

文章目录 一、zabbix概述1、定义2、zabbix监控原理3、监控对象4、zabbix的3种架构&#xff08;1&#xff09; C/S架构&#xff08;2&#xff09;分布式架构&#xff1a;zabbix-proxy-client架构&#xff08;3&#xff09; master-node-client架构 5、zabbix监控模式 二、部署za…

Apollo Planning2.0决策规划算法代码详细解析 (1):环境搭建

背景: apollo开源团队近期更新了planning版本,对代码进行了一定程度上的重构。 重构后代码结构更加清晰,对扩展更为友好;此外,也更新了dreamview对pnc的支持,使得调试更加方便。 本教程将继续更新对于Apollo Planning2.0决策规划算法代码的详细解析,便于大家更好理解…

[鹏城杯 2022]简单包含

直接用php&#xff1a;// 有wtf 加脏数据绕过

Spring boot中的线程池-ThreadPoolTaskExecutor

一、jdk的阻塞队列&#xff1a; 二、Spring boot工程的有哪些阻塞队列呢&#xff1f; 1、默认注入的ThreadPoolTaskExecutor 视频解说&#xff1a; 线程池篇-springboot项目中的service层里简单注入ThreadPoolTaskExecutor并且使用_哔哩哔哩_bilibili 程序代码&#xff1a;…

Impala实践:解析glog打印的 C++ 报错堆栈

Impala实践&#xff1a;解析glog打印的 C 报错堆栈 Impala使用glog生成日志。生产环境用的都是release build&#xff0c;glog产生的报错堆栈里没有函数名&#xff0c;很难像Java报错堆栈那样方便定位问题。下面是 Impalad 日志中的一个报错&#xff1a; I0522 09:07:16.0020…

浅复制和深复制(使用python)

在编程语言中&#xff0c;复制通常是通过赋值操作来实现的。具体实现方式可能因编程语言而异。 1. 浅复制&#xff08;Shallow Copy&#xff09; 浅复制是指创建一个新对象&#xff0c;新对象的内容是原始对象的引用。换句话说&#xff0c;新对象和原始对象共享相同的数据&am…