head

Display the beginning of the file.

Summary

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

The main purpose

Options

-c, --bytes=[-]NUM displays the first NUM bytes; if there is "-" before NUM, then other contents except NUM bytes at the end of the file will be printed.
-n, --lines=[-]NUM displays the first NUM lines instead of the default 10 lines; if there is a "-" before NUM, other lines except the NUM line at the end of the file will be printed.
-q, --quiet, --silent Do not print filename lines.
-v, --verbose Always print filename lines.
-z, --zero-terminated Line terminator is NUL instead of newline.
--help Display help information and exit.
--version Display version information and exit.

NUM can have a multiplier suffix:
b 512
kB 1000
k 1024
MB 1000*1000
M 1024*1024
GB 1000*1000*1000
G 1024*1024*1024
T, P, E, Z, Y, etc. and so on.

Binary prefixes can also be used:
KiB=K
MiB=M
And so on.

Parameters

FILE (optional): The file to be processed, which can be one or more.

return value

Returning 0 indicates success, returning a non-zero value indicates failure.

example

# View the first 6 lines of the history file:
[user2@pc ~]$ head -n 6 ~/.bash_history
#1575425555
cd ~
#1575425558
ls -lh
#1575425562
vi ~/Desktop/ZhuangZhu-74.txt
# View multiple files:
[user2@pc ~]$ head -n ~/.bash_history ~/.bashrc
==> /allhome/user2/.bash_history <==
#1575425555
cd ~
#1575425558
ls -lh
#1575425562
vi ~/Desktop/ZhuangZhu-74.txt
#1575425566
uptime
#1575425570
find ~/ -maxdepth 3 -name 'test.sh' -exec lh {} \;

==> /allhome/user2/.bashrc <==
# .bashrc

# forbid use Ctrl+D to exit shell.
set -o ignoreeof

# Source global definitions.
if [ -f /etc/bashrc ]; then
         ./etc/bashrc
fi

Notice