文本处理CLI Manual
$head
Output the first part (top lines) of text files.
命令语法POSIX Standard
head [OPTIONS] [FILE...]在交互式终端沙盒中实时运行
无需安装的客户端实时仿真环境。
bash — terminal
AST Sandbox (Free)
概述与工作原理
`head` outputs the beginning portion of files, displaying the first 10 lines by default. It is ideal for quickly inspecting file headers, CSV schemas, or top log entries without loading massive files into memory.
常用参数与选项说明
| Flag / Option | Description |
|---|---|
| -n [NUM] | Print the first NUM lines instead of the default 10. |
| -c [NUM] | Print the first NUM bytes of each file. |
| -q | Quiet mode; never print headers giving file names. |
实际生产案例与代码范例
#1View top 5 lines of syslog
head -n 5 /var/log/syslogExtracts and prints only the first 5 lines of the system log file.
相关 Linux 常用命令
$grep文本处理
使用正则表达式或匹配字符串在文本文件与输出流中搜索内容。
$cat文件操作
连接文件并在终端标准输出上打印文件内容。
$tail文本处理
Output the last part (bottom lines) of files or stream real-time logs.
$wc文本处理
Print newline, word, and byte counts for files.
$echo文本处理
Print text strings or write data to files using shell redirection.
$sed文本处理
Stream editor for filtering and transforming text using pattern substitutions.