head

Print the first 10 lines of each file(s) to standard output. With more than one file , precede each with a header giving the file name.

Syntax: head [option] files

Example:

  1. Simple usage of head. This example shows head outputting 10 lines.

    /var/log$ head dpkg.log
    2020-04-16 16:06:48 startup packages remove
    2020-04-16 16:06:48 status installed linux-virtual:amd64 4.15.0.96.87
    2020-04-16 16:06:48 remove linux-virtual:amd64 4.15.0.96.87 <none>
    2020-04-16 16:06:48 status half-configured linux-virtual:amd64 4.15.0.96.87
    2020-04-16 16:06:48 status half-installed linux-virtual:amd64 4.15.0.96.87
    2020-04-16 16:06:48 status config-files linux-virtual:amd64 4.15.0.96.87
    2020-04-16 16:06:48 status config-files linux-virtual:amd64 4.15.0.96.87
    2020-04-16 16:06:48 status config-files linux-virtual:amd64 4.15.0.96.87
    2020-04-16 16:06:48 status not-installed linux-virtual:amd64 <none>
    2020-04-16 16:06:48 status installed linux-headers-virtual:amd64 4.15.0.96.87
    
  2. Use -n command to specify the number of lines to print. We print 3 lines in this example.

    /var/log$ head -n3 dpkg.log
    2020-04-16 16:06:48 startup packages remove
    2020-04-16 16:06:48 status installed linux-virtual:amd64 4.15.0.96.87
    2020-04-16 16:06:48 remove linux-virtual:amd64 4.15.0.96.87 <none>
    

    <aside> 💡 The n in the option can be skipped and only the number can be written.

    </aside>

  3. A useful option is -f or --follow which is used to follow the file. As the file grows the new lines of the file will be displayed on the output.search for files in a directory hierarchy


tail

Print the last 10 lines of each file(s) to standard output. With more than one file, precede each with a header giving the file name.

The options available for both head and tail are similar.


find

Search for files in a directory hierarchy. Wild cards can be used while searching for files.

Syntax: find [option] filename

Example:

  1. Searching for log files.

    /var/log$ find *.log
    alternatives.log
    dpkg.log
    

wc

Print newline, word, and byte (in this order) counts for each file.