If you’ve messed around with Linux, you might well have used the “tail” command. All it does is print the last few lines of a file. For example,
tail -n 10 /var/log/apache2/access.log
will show you the last 10 pages that the webserver served. (Assuming you’re running the 2.x version of Apache.)
But for extra geeky thrills, the -f option will make tail watch the file and print out any new lines as they appear. So:
tail -f /var/log/apache2/access.log
will print out whatever Apache is putting into the log file as it is putting it in. Handy for keeping an eye on log files when you’re debugging stuff.
You can crank the geeky thrills up another level by pipelining it into something else, like our old friend from Unix school, grep
. For instance,
tail -f /var/log/apache2/access.log |grep sheep
will alert you whenever anyone tries to access a page with “sheep” in the filename. How useful!
PS: press Ctrl-C to exit.