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

ubuntu blog 1

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

The tail command is a good way to check part of a file or the last logs recorded in a log file. It also gives you the ability to check logs as they are generated.

1. tail

Will print the last 10 lines of a file

root@VPS2:/var/log# tail 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. tail -n

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

root@VPS2:/var/log# tail -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

3. tail -f

This will track the file and display any additions to the file or log file.

tail -f syslog

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

Leave A Comment

What’s happening in your mind about this post !

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