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

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 lastNUM bytes of each file-n, --lines=[-]NUM       print the first NUM lines instead of the first 10;with the leading '-', print all but the lastNUM 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 exitNUM 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 tooutput 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=Nwith --follow=name, reopen a FILE which has notchanged size after N (default 5) iterationsto 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 atleast 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 exitNUM 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.rhkb.cn/news/88637.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Baumer工业相机堡盟工业相机如何通过BGAPISDK设置相机的固定帧率(C#)

Baumer工业相机堡盟工业相机如何通过BGAPI SDK设置相机的固定帧率&#xff08;C#&#xff09; Baumer工业相机Baumer工业相机的固定帧率功能的技术背景CameraExplorer如何查看相机固定帧率功能在BGAPI SDK里通过函数设置相机固定帧率 Baumer工业相机通过BGAPI SDK设置相机固定帧…

剑指 Offer 32 - II. 从上到下打印二叉树 II

题目描述 从上到下按层打印二叉树&#xff0c;同一层的节点按从左到右的顺序打印&#xff0c;每一层打印到一行。 示例 思路 采用队列存储二叉树&#xff0c;利用BFS算法对树进行从上到下的层次遍历 如何存储每一层的元素&#xff1f;——利用for循环把当前队列的元素存储进…

计算机基础概论

一、计算机的组成 1.计算机组成的五大部件 &#xff08;1&#xff09;运算器&#xff1a;也叫算术逻辑单元&#xff0c;完成对数据的各种常规运算&#xff0c;如加减乘除&#xff0c;也包括逻辑运算&#xff0c;位移&#xff0c;比较等。 &#xff08;2&#xff09;控制器&a…

Linux 共享内存mmap,进程通信

文章目录 前言一、存储映射 I/O二、mmap&#xff0c; munmap三、父子进程间 mmap 通信四、非血缘关系进程间 mmap 提通信五、mmap 匿名映射区总结 前言 进程间通信是操作系统中重要的概念之一&#xff0c;使得不同的进程可以相互交换数据和进行协作。其中&#xff0c;共享内存…

.bit域名调研

.bit域名研究 问题&#xff1a; .bit域名和ENS域名的相同点&#xff1f;不同点&#xff1f;有什么关系&#xff1f; .bit的定义 .bit 是基于区块链的&#xff0c;开源的&#xff0c;跨链去中心化账户系统.bit 提供了以 .bit 为后缀的全局唯一的命名体系&#xff0c;可用于加密…

SpringBoot复习:(36)国际化

一、Resources目录下建立一个目录&#xff08;比如international)来存储资源文件 message.properties 空的&#xff0c;但不能没有 message_zh_CN.properties hello您好message_en_us.properties hellohello world二、自动配置类MessageSourceAutoConfiguration 常量MESSAGE…

学习笔记整理-JS-02-基本类型

文章目录 一、数据类型简介和检测1. JavaScript中两大数据类型 二、基本数据类型1. 数字类型2. 字符串类型3. 布尔类型4. undefined类型5. null 三、数据类型的转换1. 数据类型的转换 四、重点内容 一、数据类型简介和检测 1. JavaScript中两大数据类型 基本数据类型 Number S…

【Linux 网络】 数据链路层协议

数据链路层协议 数据链路层解决的问题以太网协议认识以太网以太网帧格式 认识MAC地址对比理解MAC地址和IP地址认识MTUMTU对IP协议的影响MTU对UDP协议的影响MTU对于TCP协议的影响ARP协议ARP协议的作用ARP协议的工作流程ARP数据报的格式 总结 数据链路层解决的问题 IP拥有将数据跨…

认识 spring 中的事务 与 事务的传播机制

前言 本篇介绍spring中事务的实现方式&#xff0c;如何实现声明式事务&#xff0c;对事物进行参数的设置&#xff0c;了解事务的隔离级别和事务的传播机制&#xff1b;如有错误&#xff0c;请在评论区指正&#xff0c;让我们一起交流&#xff0c;共同进步&#xff01; 文章目录…

python环境下载安装教程,python运行环境怎么下载

本篇文章给大家谈谈python安装步骤以及环境变量配置&#xff0c;以及下载python需要设置环境变量吗&#xff0c;希望对各位有所帮助&#xff0c;不要忘了收藏本站喔。 1.https://www.python.org/downloads/windows/ 下载适合自己电脑的python安装包 2.下载后安装即可 3.配置环…

FastAPI和Flask:构建RESTful API的比较分析

Python 是一种功能强大的编程语言&#xff0c;广泛应用于 Web 开发领域。FastAPI 和 Flask 是 Python Web 开发中最受欢迎的两个框架。本文将对 FastAPI 和 Flask 进行综合对比&#xff0c;探讨它们在语法和表达能力、生态系统和社区支持、性能和扩展性、开发工具和调试支持、安…

LVS集群和nginx负载均衡

目录 1、基于 CentOS 7 构建 LVS-DR 群集。 2、配置nginx负载均衡。 1、基于 CentOS 7 构建 LVS-DR 群集。 1.部署LVS负载调度器 1>安装配置工具 [rootnode6 ~]# yum install -y ipvsadm 2>配置LVS虚拟IP&#xff08;VIP地址&#xff09; [rootnode6 ~]# ifconfig ens…

测试开发探索:“WeTalk“网页聊天室的测试流程与自动化

目录 引言&#xff1a; 测试开发目标&#xff1a; "WeTalk"项目背景 关于登录测试用例的设计 测试开发策略与流程 集成测试&#xff1a;Selenium JUnit 接口测试&#xff1a;Postman 测试用例的设计与实现 自动化测试演示&#xff1a; 用例一&#xff1a;登…

vulnhub靶机Deathnote

难度&#xff1a;easy 下载地址&#xff1a;https://download.vulnhub.com/deathnote/Deathnote.ova 主机发现 arp-scan -l 端口扫描 nmap --min-rate 10000 -p- 192.168.21.140 进一步查看目标的端口的服务和版本 nmap -sV -sT -O -p22,80 192.168.21.140 扫描端口的漏洞…

CNN(四):ResNet与DenseNet结合--DPN

&#x1f368; 本文为&#x1f517;365天深度学习训练营中的学习记录博客&#x1f356; 原作者&#xff1a;K同学啊|接辅导、项目定制 前面实现了ResNet和DenseNet的算法&#xff0c;了解了它们有各自的特点&#xff1a; ResNet&#xff1a;通过建立前面层与后面层之间的“短路…

springboot生成表结构和表数据sql

需求 业务背景是需要某单机程序需要把正在进行的任务导出&#xff0c;然后另一台电脑上单机继续运行&#xff0c;我这里选择的方案是同步SQL形式&#xff0c;并保证ID随机&#xff0c;多个数据库不会重复。 实现 package com.nari.web.controller.demo.controller;import cn…

【大数据】Flink 详解(二):核心篇 Ⅱ

Flink 详解&#xff08;二&#xff09;&#xff1a;核心篇 Ⅱ 22、刚才提到 State&#xff0c;那你简单说一下什么是 State。 在 Flink 中&#xff0c;状态 被称作 state&#xff0c;是用来保存中间的计算结果或者缓存数据。根据状态是否需要保存中间结果&#xff0c;分为 无状…

OpenCV基本操作——图像的基础操作

目录 图像的IO操作读取图像显示图像保存图像 绘制几何图形绘制直线绘制圆形绘制矩形向图像中添加文字效果展示 获取并修改图像中的像素点获取图像的属性图像通道的拆分与合并色彩空间的改变 图像的IO操作 读取图像 cv2.imread()import numpy as np import cv2 imgcv2.imread(…

7-4 求整数均值

本题要求编写程序&#xff0c;计算4个整数的和与平均值。题目保证输入与输出均在整型范围内。 输入格式: 输入在一行中给出4个整数&#xff0c;其间以空格分隔。 输出格式: 在一行中按照格式“Sum 和; Average 平均值”顺序输出和与平均值&#xff0c;其中平均值精确到小…

windows10 安装WSL2, Ubuntu,docker

AI- 通过docker开发调试部署ChatLLM 阅读时长&#xff1a;10分钟 本文内容&#xff1a; window上安装ubuntu虚拟机&#xff0c;并在虚拟机中安装docker&#xff0c;通过docker部署数字人模型&#xff0c;通过vscode链接到虚拟机进行开发调试.调试完成后&#xff0c;直接部署在云…