Ubuntu: Viewing past dmesg outputs from previous sessions

 

Sometimes you may want to check the output of dmesg from a previous session. This can provide some useful information – for example, whether an error has only just started appearing or whether it was present during previous sessions. Ubuntu archives old dmesg outputs in the following location:

 

/var/log

 

We can see how many are there with the following command:

 

ls -l /var/log/dmesg*

 

This should output a listing similar to this:

 

-rw-r—– 1 root adm 17169 Jan 10 17:07 dmesg
-rw-r—– 1 root adm 17170 Jan  9 20:28 dmesg.0
-rw-r—– 1 root adm  6063 Jan  9 20:22 dmesg.1.gz
-rw-r—– 1 root adm  6076 Jan  4 22:36 dmesg.2.gz
-rw-r—– 1 root adm  6108 Jan  4 22:27 dmesg.3.gz
-rw-r—– 1 root adm  6105 Jan  3 14:16 dmesg.4.gz

You can see that the old archives are compressed. To view the compressed files without decompressing them into the folder, we use the zless command. To do so with the first archive:

 

sudo zless /var/log/dmesg.1.gz

 

If you aren’t familiar with less you press ‘q’ to quit and return you to your prompt.