How to view files and logs using the head command Linux CLI

This is a quick reference on how to view files and logs using the head command on Linux Based Operating Systems.

The head command is a good way to check the first part of a file or the first logs recorded in a log file.

1. head

Will print the first 10 lines of a file

root@VPS2:/var/log# head syslog
Jun  6 15:26:53 VPS2 systemd[1]: Stopped Network Service.
Jun  6 15:26:53 VPS2 systemd-udevd[376]: Network interface NamePolicy= disabled on kernel command line, ignoring.
Jun  6 15:26:53 VPS2 systemd[1]: Starting Network Service...
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: eth1: Gained IPv6LL
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: eth0: Gained IPv6LL
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: Enumeration completed
Jun  6 15:26:53 VPS2 systemd[1]: Started Network Service.
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: eth1: Link is not managed by us
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: lo: Link is not managed by us
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: eth0: Configured
root@VPS2:/var/log#

2. head -n

You can specify the number lines printed by using -n option.

root@VPS2:/var/log# head -n 5 syslog
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: Enumeration completed
Jun  6 15:26:53 VPS2 systemd[1]: Started Network Service.
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: eth1: Link is not managed by us
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: lo: Link is not managed by us
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: eth0: Configured

If you are new to the world of Linux, an avid Linux enthusiast or a student why not try our 0.99p per month Linux VPS.

Simply click on the screen shot below to find out more or navigate to https://piggybank.cloud

Thank you for reading and please feel free to leave any feedback.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s