Head


From Linuxconfig.org

Jump to: navigation, search

.. back to the list of Linux Commands

Name

head - output the first part of files

Synopsis - man page

head [OPTION]... [FILE]...

Frequently used options

-c, --bytes=[-]N
      print the first N bytes of each  file;  with  the  leading  `-',
      print all but the last N bytes of each file
-n, --lines=[-]N
      print  the first N lines instead of the first 10; with the leading `-', 
      print all but the last N lines of each file

Examples

Command head will by default print first 10 lines of a file. Lets prove it by creating test file from /etc/services which contains line numbers.

$ cat /etc/services | nl > /tmp/services.txt
Image:head01.gif
$ head /tmp/services.txt
Image:head02.gif

with -n option we can instruct head command to print desired number of lines.

$ head -n /tmp/services.txt
Image:head03.gif

it is possible to do the same trick just with -5 option:

$ head -5 /tmp/services.txt
Image:head04.gif

Same as with option -n with option -c we can print out number of bytes to the standard output. Lets do small test:

$ wc -l -c services.txt
$ head -c 22173 /tmp/services.txt | wc -l
Image:head05.gif

.. back to the list of Linux Commands

Personal tools
Linux Commands