View kernel log linux

How to View System Log Files in Linux

This article will explain how to view various log files scattered throughout the Linux file system. Log files are useful for finding out system anomalies and can help in developing fixes for them. All the commands listed below are tested in Ubuntu 20.04 LTS version, but they should work in other Linux distributions as well. In case you are not able to find certain log files, you can use the “Locate” command, which can be installed in your system through the package manager.

GNOME Logs

GNOME Logs is a graphical log viewer shipped by default in most GNOME Shell based Linux distributions. It shows all logs generated for systemd journals. Systemd manages all services running on your system and it is responsible for starting, stopping and monitoring various services that are launched at boot. GNOME Logs neatly categorises logs in various headings and you can export these logs to text files. It also allows you to search and refine log messages using various filters.

To install GNOME Logs in Ubuntu, run the command below:

You can install GNOME Logs in other Linux distributions by searching for it in the package manager shipped with your distribution. Alternatively, you can compile it from source code.

Linux Kernel Logs

To view kernel logs in terminal, run the command below:

You can also open the log file in any text editor of your choice. The screenshot above shows the usage of “tail” command after the pipe symbol. It ensures that only the last few lines are shown as the output (two lines in this case).

To view kernel logs for previous boot, run the command below:

X11 Logs

Logs for X11 Xorg display server can be found at two locations depending on your Linux distribution. The logs can be located at either “/var/log/” or “$HOME/.local/share/xorg/” directories. You can find correct location of Xorg log files by running the command below:

The “0” part in the file name denotes identification number for the connected monitor. If you have only one display connected to your system, the file name should be “Xorg.0.log”. In case of multi-monitor setups, multiple log files will be recorded, one for each monitor. For instance, in multi-monitor setups, file names could be “Xorg.0.log”, “Xorg.1.log” and so on.

To view these logs using “less” command, use the following command:

Читайте также:  Создание rpm пакет linux

“Less” command shortens terminal output and allows you to interactively navigate to the next line of the terminal output using key.

Dmesg

Dmesg prints kernel log messages or “ring buffer” of the Linux kernel. It is used to examine and debug all the output generated by the kernel, especially messages related to connected hardware and their drivers.

Run the following commands to view dmesg log:

You can check all command line arguments for dmesg by running the following command in a terminal:

Boot Messages

To view boot messages log, run the command below:

To view logs for previous boot, run the command below:

System Logs

System log files record a variety of messages useful for debugging. If you cannot find certain log messages in other files, chances are that they could be in syslog files.

To view current and previous syslog files respectively, run the following commands:

Authorization Logs

Authorization Logs or simply “Auth” logs record remote login attempts and password prompts requested by sudo command. To view these logs, use the following commands:

Login Logs

“Faillog” records failed login attempts while “Lastlog” shows information about last login. Run the following commands to see login records:

Third Party Application Logs

User installed third party applications do not have root access. In case they are recording any logs, they should be in the directory of the executable file or at the following locations:

Conclusion

Examining various log files can help in debugging system freeze and crash issues, especially when new and unsupported hardware is present in the PC. These log files are also useful for finding out security breaches or security loopholes if there are any. If you are getting unexpected behavior from software installed on your system or frequent reboots and crashes, the first thing you should do is to examine various system log files.

About the author

Nitesh Kumar

I am a freelancer software developer and content writer who loves Linux, open source software and the free software community.

Источник

How to View & Read Linux Log Files

All Linux systems create and store information log files for boot processes, applications, and other events. These files can be a helpful resource for troubleshooting system issues.

Most Linux log files are stored in a plain ASCII text file and are in the /var/log directory and subdirectory. Logs are generated by the Linux system daemon log, syslogd or rsyslogd.

This tutorial will walk you through how to find and read Linux log files, and configure the system logging daemon.

Tutorial on how to view and read Linux log files.

How to View Linux Logs

1. First, open the Linux terminal as a root user. This will enable root privileges.

2. Use the following command to see the log files:

3. To view the logs, type the following command:

The command displays all Linux log files, such as kern.log and boot.log. These files contain the necessary information for the proper function of the operating system.

Читайте также:  Запуск приложения команда linux

How to list all Linux log files in command line.

Log files are accessed using root privileges. By definition, root is the default account that has access to all Linux files.

Use the following example line command to access the respective file:

sudo less [log name here].log

This command displays a timeline of all information related to that operation.

Note that log files are stored in plain text so they can be viewed by using the following standard commands:

zcat – Displays all the contents of logfile.gz

zmore – See the file in pages, without decompressing the files

zgrep – Search inside a compressed file

grep – Find all occurrences of a search term in a file or filter a log file

head – View the very beginning of text files

Note: Check out our comprehensive guide on grep to learn how to use it with examples.

Important Linux System Logs

Logs can tell a lot about the operations of a system. A good understanding of each type of file will help how to distinguish the respective logs.

Most directories can be grouped into one of four categories:

Many of these logs can be located in the var/log subdirectory.

System Logs

Systems log files are needed for Linux to work. On its own, it contains the most significant amount of information about system functionality. The most common log files are:

  • /var/log/boot.log : System Boot log (the boot log stores all information related to booting operations)
  • /var/log/auth.log : Auth logs (the authentication log stores all authentication logs, including successful and failed attempts)
  • /var/log/httpd/ : Apache access and error logs
  • /var/log/mysqld.log : MySQL database server log file
  • /var/log/debug : Debug logs (the debug log stores detailed messages related to debugging and is useful for troubleshooting specific system operations)
  • /var/log/daemon.log : Daemon logs (the daemon log contains information about events related to running the Linux operation)
  • /var/log/maillog : Mail server logs (the mail log stores information related to mail servers and archiving emails)
  • /var/log/kern.log : Kernel logs (the kernel log stores information from the Ubuntu Linux kernel)
  • /var/log/yum.log : Yum command logs

System Logging Daemon

A daemon log is a program that runs in the background and is essential for system operations. These logs have their own category of logs and are seen as the heart of the logging operations for any system.

The path for the system login daemon’s configuration is /etc/syslog.conf .

Each file consists of a selector and an action entry field. The syslogd daemon can forward log messages as well. This can be useful for debugging purposes.

Application Logs

Application logs store information relevant to any application that is executed. This can include error messages, signs of system compromise, and browser identification string.

Log files that fall into this category include CUPS Print System logs, Rootkit Hunter log, Apache HTTP server logs, Samba SMB server logs, and X11 server log.

Non-Human-Readable Logs

Not all logs are designed in a human-readable format. Some are designed only to be read by system applications. Such files are often related to login information. They include login failure logs, last logins logs, and login records.

Читайте также:  Need for speed the run linux

There are tools and software for reading Linux log files. They are not necessary for reading files as most can be read directly from the Linux terminal.

Supplemental GUIs for Viewing Linux Log Files

System Log Viewer is a GUI that can be used to monitor system logs.

The interface provides several functions for managing logs, including a log statistics display. It is a user-friendly log monitoring GUI.

  • A live view of logs
  • Number of lines in the log
  • Log size
  • Most recent log dates
  • Modifications made to logs
  • Filters
  • Keyboard Shortcuts

Alternatively, use Xlogmaster which can monitor a considerable number of log files. It features three different modes:

  • Run mode: Starts a specified program and obtains stdout
  • Cat mode: Cats files within specified intervals
  • Tail mode: Checks log files within regular intervals

Xlogmaster is useful for increasing security. It translates all data for highlighting, hiding lines, and displays this information for taking user requested action.

How to Configure Log Files on Ubuntu and CentOS

This section explains different mechanisms for configuring log files. Let’s start with a CentOS example.

To view users currently logged onto a Linux server, enter the who command as a root user:

List users that are logged into the Linux system.

This also lists the login history of users. To view the login history of the system administrator, enter the following command:

View login hisotry of the system administrator.

To view information of the last login, enter:

View information of the last login onto Linux system.

Execute Log Rotation

Log files that have zeroes appended at the end are rotated files. That means log file names have automatically been changed within the system.

The purpose of log rotation is to compress outdated logs that are taking up space. Log rotation can be done using the logrotate command. This command rotates, compresses, and mails system logs.

logrotate handles systems that create significant amounts of log files. The command is used by the cron scheduler and reads the logrotate configuration file /etc/logrotate.conf . It’s also used to read files in the logrotate configuration directory.

To include additional functionality to logrotate, start by entering the following command:

It compresses and resizes the desired log file.

The commands perform the actions as follows:

missingok – Tells logrotate not to output an error if a log file is missing

notifempty – Does not rotate the log file if it is empty. It reduces the size of the log file with gzip

size – Ensures that the log file does not exceed the specified dimension and rotates it otherwise

daily – Rotates the log files on a daily schedule. This can also be done on a weekly or monthly schedule

create – Instantiates a log file where the owner and group are a root user

A thorough understanding of how to view and read Linux logs is necessary for troubleshooting a Linux system.

Using the proper commands and tools can simplify this process.

Источник

Оцените статью
Adblock
detector