Categories
Linux Tutorial Series

Linux Tutorial Series – 45 – head and tail commands

Here is the video version, if you prefer it:

The head command is used to display the first 10 lines of a file. The tail command is used to display the last 10 lines of the file. (Barrett, 2016)

Both of the commands have an option -n which control how many lines you want to output. By default it is 10, but you could write

head -n 12

and head would output 12 lines at the beginning of the file.

A really cool thing about tail is that it has the -f option, which enables you to watch a file actively; you get new lines which are written to a file displayed. Why is this useful? Well, if you are watching some system file (a file which contains information about devices connected to your computer, for example), you could find out some information about the newly connected device.

Hope you learned something new!

References

Barrett, D. J. (2016). Linux pocket guide (3rd ed.). O’Reilly Media. Pages 60-61

NewsletterUpdates on interesting things I am doing

Subscribe to my newsletter to keep abreast of the interesting things I'm doing. I will send you the newsletter only when there is something interesting. This means 0% spam, 100% interesting content.

Leave a Reply

Your email address will not be published. Required fields are marked *