The head and tail Commands

In Chapter 3, “Working with Files,” you looked at viewing the contents of a file using the cat command. This command enables you to view an entire file, but often you need more control over lines that are displayed. The head and tail commands provide some of this control.

The head Command

The head command is used to display the first few lines of a file. Its basic syntax is

head [-n lines] files
						

Here files is the list of the files you want the head command to process. Without the -n lines option, the head command shows the first 10 lines of its standard input. When this option is specified, head shows the number of lines specified by lines instead.

On some versions of Linux the output from the -n lines option might ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.