UNPKG

2.04 kBMarkdownView Raw
1head
2===
3
4显示文件的开头部分。
5
6## 概要
7
8```shell
9head [OPTION]... [FILE]...
10```
11
12## 主要用途
13
14- 在未指定行数时默认显示前10行。
15- 处理多个文件时会在各个文件之前附加含有文件名的行。
16- 当没有文件或文件为`-`时,读取标准输入。
17
18## 选项
19
20```shell
21-c, --bytes=[-]NUM 显示前NUM字节;如果NUM前有"-",那么会打印除了文件末尾的NUM字节以外的其他内容。
22-n, --lines=[-]NUM 显示前NUM行而不是默认的10行;如果NUM前有"-",那么会打印除了文件末尾的NUM行以外的其他行。
23-q, --quiet, --silent 不打印文件名行。
24-v, --verbose 总是打印文件名行。
25-z, --zero-terminated 行终止符为NUL而不是换行符。
26--help 显示帮助信息并退出。
27--version 显示版本信息并退出。
28
29NUM可以有一个乘数后缀:
30b 512
31kB 1000
32k 1024
33MB 1000*1000
34M 1024*1024
35GB 1000*1000*1000
36G 1024*1024*1024
37T、P、E、Z、Y等以此类推。
38
39也可以使用二进制前缀:
40KiB=K
41MiB=M
42以此类推。
43```
44
45## 参数
46
47FILE(可选):要处理的文件,可以为一或多个。
48
49## 返回值
50
51返回0表示成功,返回非0值表示失败。
52
53## 例子
54
55```shell
56# 查看历史文件的前6行:
57[user2@pc ~]$ head -n 6 ~/.bash_history
58#1575425555
59cd ~
60#1575425558
61ls -lh
62#1575425562
63vi ~/Desktop/ZhuangZhu-74.txt
64```
65
66```shell
67# 查看多个文件:
68[user2@pc ~]$ head -n ~/.bash_history ~/.bashrc
69==> /allhome/user2/.bash_history <==
70#1575425555
71cd ~
72#1575425558
73ls -lh
74#1575425562
75vi ~/Desktop/ZhuangZhu-74.txt
76#1575425566
77uptime
78#1575425570
79find ~/ -maxdepth 3 -name 'test.sh' -exec lh {} \;
80
81==> /allhome/user2/.bashrc <==
82# .bashrc
83
84# forbid use Ctrl+D to exit shell.
85set -o ignoreeof
86
87# Source global definitions.
88if [ -f /etc/bashrc ]; then
89 . /etc/bashrc
90fi
91
92```
93
94
95### 注意
96
971. 该命令是`GNU coreutils`包中的命令,相关的帮助信息请查看`man -s 1 head``info coreutils 'head invocation'`
98
99