Follow the Tail

04 February 2014

One way to spot errors and see what’s going on is to follow the log files. On most Linux systems, there are plenty of logs to follow - the web server, the database and plenty of other components in the technology stack - and even a syslog for “generic system events”. You find many of the generated logs in the /var/log/ directory on most modern Linux systems.

Once you found an interesting logfile you have a few simple commands available to see the contents.

  • The head command will show you the top most lines of the file.
  • The cat command will print the entire contents of the log (to the screen).
  • You can pipe the output of the cat command to more to get a nice page by page view (you pipe by writing cat filename | more).
  • The tail command will show you the last lines of the log file.

If you want to see what’s happening continuously in a file, you can use the follow option with the tail command - tail -f filename - and until you press control + c any new lines in the log will be printed to the screen.