Exploring head and tail - Linux Commands

| 2 min read

What are the head and tail Commands in Linux?

The head and tail commands are used to display the beginning and end sections of a file, respectively. These commands are useful for quickly viewing the contents of a file without opening it in an editor.

Basic Syntax:

By default, both commands will display the first or last 10 lines of file contents respectively.

head:

head [option] [file]

tail:

tail [option] [file]

Options

  • Options for head
OptionDescription
-n, —linesPrint the first n lines instead of the first 10
-c, —bytesPrint the first c bytes of each file
-q, —quiet, —silentNever print headers giving file names
-v, —verboseAlways print headers giving file names
  • Options for tail
OptionDescription
-n, —linesPrint the first n lines instead of the first 10
-c, —bytesPrint the first c bytes of each file
-f, —followOutput appended data as the file grows
-q, —quiet, —silentNever print headers giving file names
-v, —verboseAlways print headers giving file names

Additional Help

You can explore more by using the commands:

# head
head --help
# or
man head

# tail
tail --help
# or
man tail

Thank you!

Thank you for your time and for reading this!