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
Option | Description |
---|---|
-n, âlines | Print the first n lines instead of the first 10 |
-c, âbytes | Print the first c bytes of each file |
-q, âquiet, âsilent | Never print headers giving file names |
-v, âverbose | Always print headers giving file names |
- Options for
tail
Option | Description |
---|---|
-n, âlines | Print the first n lines instead of the first 10 |
-c, âbytes | Print the first c bytes of each file |
-f, âfollow | Output appended data as the file grows |
-q, âquiet, âsilent | Never print headers giving file names |
-v, âverbose | Always 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!