How do I get information from the logs on my computer when I only have access to the command line?

For various reasons I can no longer access my graphical desktop, and can only login via a tty (Ctrl+Alt+F1 through F6 by default).

To help diagnose and solve my problem I need to look through the logs and maybe put some of the info into my question or forum thread.

How can I get this information?


Solution 1:

First here is a list of some of the common log files and what they contain:

  • /var/log/messages : General message and system related stuff
  • /var/log/auth.log : Authenication logs.
  • /var/log/kern.log : Kernel logs.
  • /var/log/cron.log : Cron daemon logs.
  • /var/log/Xorg.0.log : Log for the X server.
  • ~/.xsession-errors : Logs related to the last X session (and the one before that, in xsession-errors.old)

After you've logged into the tty it's a good idea to move to the folder where the logs are located (usually /var/log). For this we use the cd command:

cd /var/log  

Now that we're in the folder where the logs are stored we use the ls command to see what logs exist:

ls -a

There will probably be quite a few, these instructions should apply to all of them.

Once you find a log you want to view, you can use the less command:

less kern.log  

Use the up/down arrow keys to browse through the file. When you're done, press Q to quit less. If you want to search the logs for a certain keyword you can use grep:

sudo grep "apparmor" kern.log 

Grep also accepts regular expressions. See man grep for more information.

If you just need the output of a certain command see this question about saving terminal output to a file which you can then give to someone assisting you following one of the methods below.


This is all shiny and great you might say, but I don't have a single clue what I'm looking for, and I just need to give the log file to someone else to help me. We can do that too!

If you are getting help from someone on the internet (like this site!) the best way to share this information with them is to upload the file(s) to http://paste.ubuntu.com and provide them with the link. If your machine has an active internet connection you can do this in one step as described in method 2, otherwise follow the steps in method 1 and upload the files from another computer that can access the internet.

Method 1: Put them on external media..

such as a flash drive or SD card. Plug one in. Ubuntu should automatically mount it in /media so run

ls /media  

If you see the name of your flash drive/SD card there then you can continue. Otherwise you'll have to mount it manually. (don't worry! It isn't scary at all).

Once you have your drive mounted you can use the cp command to copy over any logs or files you need:

cp /var/log/kern.log /media/myFlashDrive/

When you're done unmount the drive:

sudo umount /media/myFlashDrive  

Method 2: Upload the files directly to a pastebin..

like paste.ubuntu.com. For this use the pastebinit command. First we need to install pastebinit:

sudo apt-get install pastebinit  

then upload the files like so:

pastebinit file1 file2 file3  

Where file1 file2 file3 is a space delimited list of the files you would like to upload. For example, if I was uploading kern.log and Xorg.0.log I would use the command:

pastebinit /var/log/kern.log /var/log/Xorg.0.log  

Pastebinit will return a link for each file uploaded. Share these links with the people helping you.