Sometime we want to see what has happened or watch what is happening in realtime by reading the "log" files. To do this, we can use tail command. Assuming that we want to read Apache error log file. You can read any log files with it such as system logs "/var/log/syslog".


Read last 5 log messages


inanzzz@inanzzz:~$ tail -n5 /var/log/apache2/error.log
[Sat Mar 28 09:29:23.375241 2015] [mpm_prefork:notice] [pid 5557] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.5 configured -- resuming normal operations
[Sat Mar 28 09:29:23.375337 2015] [core:notice] [pid 5557] AH00094: Command line: '/usr/sbin/apache2'
[Sat Mar 28 09:31:00.201426 2015] [mpm_prefork:notice] [pid 5557] AH00169: caught SIGTERM, shutting down
[Sat Mar 28 09:31:01.291222 2015] [mpm_prefork:notice] [pid 5643] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.5 configured -- resuming normal operations
[Sat Mar 28 09:31:01.291321 2015] [core:notice] [pid 5643] AH00094: Command line: '/usr/sbin/apache2'

Watch logs in realtime


inanzzz@inanzzz:~$ tail -f /var/log/apache2/error.log
[Sat Mar 28 09:20:34.641915 2015] [core:notice] [pid 5284] AH00094: Command line: '/usr/sbin/apache2'
[Sat Mar 28 09:26:16.628067 2015] [mpm_prefork:notice] [pid 5284] AH00169: caught SIGTERM, shutting down
[Sat Mar 28 09:26:17.746466 2015] [mpm_prefork:notice] [pid 5435] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.5 configured -- resuming normal operations
[Sat Mar 28 09:26:17.746565 2015] [core:notice] [pid 5435] AH00094: Command line: '/usr/sbin/apache2'
[Sat Mar 28 09:29:22.232717 2015] [mpm_prefork:notice] [pid 5435] AH00169: caught SIGTERM, shutting down
[Sat Mar 28 09:29:23.375241 2015] [mpm_prefork:notice] [pid 5557] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.5 configured -- resuming normal operations
[Sat Mar 28 09:29:23.375337 2015] [core:notice] [pid 5557] AH00094: Command line: '/usr/sbin/apache2'
[Sat Mar 28 09:31:00.201426 2015] [mpm_prefork:notice] [pid 5557] AH00169: caught SIGTERM, shutting down
[Sat Mar 28 09:31:01.291222 2015] [mpm_prefork:notice] [pid 5643] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.5 configured -- resuming normal operations
[Sat Mar 28 09:31:01.291321 2015] [core:notice] [pid 5643] AH00094: Command line: '/usr/sbin/apache2'