Linux bash head and tail commands


The head and tail commands display the beginning and end of a file respectively. By default, these commands display 10 lines, but they both have a –n option that allows a different number of lines to be specified. The file to display is passed as an argument to these commands.


Head command shows the first 10 lines of a file

[root@CentOs ~]# head /etc/passwd

Head command shows the first 10 lines of a file


Tail command shows the last 10 lines of a file

[root@CentOs ~]# tail /etc/passwd

Tail command shows the last 10 lines of a file


Head command with -n option

[root@CentOs ~]# head -n 5 /etc/passwd

Head command with -n option

For more options see head man page


Tail command with -n option

[root@CentOs ~]# tail -5 /etc/passwd

Tail command with -n option

For more options see tail man page






Tech info

Comments