Viewing log files
There are a number of commands to view log files.
Anytime a new entry is added to a log file, it is appended to the end of the file. This is one of those times where tail
is particularly useful. Usually when we want to look at log files we want to look at the most recent entries.
When organizing our viewing command - order matters. Most of the following commands produce different results. And all are useful depending on what type of results you want. Go through the thought process and figure out what each command does. Can you figure out which three produce identical results?
cat /var/log/syslog
cat /var/log/syslog | grep daemon
cat /var/log/syslog | grep daemon | tail -n 10
cat /var/log/syslog | tail -n 10
cat /var/log/syslog | tail -n 10 | grep daemon
less /var/log/syslog
less /var/log/syslog | tail -n 10 | grep daemon
head -n 10 /var/log/syslog
head -n 10 /var/log/syslog | grep daemon
tail -n 10 /var/log/syslog
tail -n 10 /var/log/syslog | grep daemon
If you add the -f option to the tail command it provides a live watch of the log file. This is helpful when trying to watch any error messages produced as you test certain functionality, such as logging in or running a specific program.
- Use
ctrl-c
to cancel the tail -f
command.
Note that log files show info for all users and processes. If you are looking for something specific you may want refine your results with grep
.