Linux logs give you a visual history of everything that’s been happening in the operating system. They give a useful overview of events in order to help you troubleshoot the system.
There are several log files captured by the operating system, see examples below:
System logs
These logs may contain information about authorizations, system daemons, and system messages.
Application logs
Some applications also create logs in /var/log. Below are some examples:
Non-human-readable logs.
Not all log files are meant to be readable by humans. Some were made to be parsed by applications. Below are some of examples.
Viewing Log Files
The most basic way to view files from the command line is using the cat command. You simply pass in the file name, and it outputs the entire contents of the file: cat file.txt.
This can be inconvenient when dealing with large files (which isn’t uncommon for logs). We could use an editor, although that may be overkill just to view a file.
This is where the less command comes in. We pass it the file name (less file.txt), and it will open the file in a simple interface. From here, we can use the arrow keys (or j/k if you’re familiar with Vim) to move through the file, use / to search, and press q to quit.
There are a few more features, all of which are described by pressing h to open the help menu.
If you’re running Ubuntu 17.10 or above, it will be called Logs. Otherwise, it will be under the name System Log
The log viewer has a simple interface. The sidebar on the left shows a list of open log files, with the contents of the currently selected file displayed on the right.
The log viewer not only displays but also monitors log files for changes.