Spread the love

About tail command

The tail command outputs the last part, or “tail”, of files. It can also monitor new information written to the file in real time, displaying the newest entries in a system log, for example. tail is a program available on Unix, Unix-like systems, FreeDOS and MSX-DOS used to display the tail end of a text file or piped data. By default, tail will output the last 10 lines of its input to the standard output. With command line options, the amount of output and the units (lines, blocks or bytes) may be changed.

Syntax of tail command

 tail [options] <filename>Code language: HTML, XML (xml)

Basic usage examples for output and monitoring

# Output the default 100 lines
tail /var/log/apache2/access.log

# Outputs the last 10 lines of the file
tail -n 30 /var/log/apache2/access.log

# Outputs the last 100 lines of the file
tail -f /var/log/apache2/access.log

# Outputs the last 100 lines of the file where something
tail -f /var/log/apache2/access.log | grep somethingCode language: PHP (php)


Tail usage output:

root@webleit:~# tail -n 10 /var/log/auth.log 
Feb 23 13:16:36 webleit sshd[5526]: Received disconnect from 172.92.151.71 port 55252:11: Bye Bye [preauth]
Feb 23 13:16:36 webleit sshd[5526]: Disconnected from invalid user 172.92.151.71 port 55252 [preauth]
Feb 23 13:17:01 webleit CRON[5528]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 23 13:17:01 webleit CRON[5528]: pam_unix(cron:session): session closed for user root
Feb 23 13:25:12 webleit sudo: root : TTY=pts/0 ; PWD=/root ; USER=root ; COMMAND=/bin/su
Feb 23 13:25:12 webleit sudo: pam_unix(sudo:session): session opened for user root by sonik(uid=0)
Feb 23 13:25:12 webleit su[5551]: Successful su for root by root
Feb 23 13:25:12 webleit su[5551]: + /dev/pts/0 root:root
Feb 23 13:25:12 webleit su[5551]: pam_unix(su:session): session opened for user root by sonik(uid=0)
Feb 23 13:25:12 webleit su[5551]: pam_systemd(su:session): Cannot create session: Already running in a sessionCode language: PHP (php)

Conclusion

In this article we checked some examples how to use the tail command. If you know other good examples, please tell us in the comments bellow.

We hope you enjoyed this article. if that is so please rate this page with the stars bellow and subscribe to our YouTube channel or follow us on twiter.

Leave a Reply