Viewing Beginning and Ending Contents of Files

Learn the commands to display the beginning and ending contents of any file.

We can use head and tail to view beginning and ending contents of file.

head:

Definition:

head, by default, prints the first 10 lines of each file to standard output. It reads the first few lines of any text given to it as an input and writes them on the display screen.

Syntax:

head [options] [file(s)]

Options:

Option Description
-n It can be used followed by an integer representing the number of lines to be displayed.
-c This option can be used followed by the number of bytes desired.
-q (quiet) Never print headers identifying file names.
-v (verbose) Always print headers identifying file names.

Example:

  • To display first 15 lines from a file:
head -n 15 myFile.txt

Get hands-on with 1200+ tech skills courses.