How to Use Linux Journalctl Command?

14

Linux-based systems provide multiple tools that help record and analyze system logs. Just like the “systemd”, which is a powerful tool used to collect logs from the sources in a binary format and allows the user to get the logs using command-line.

The logs we discussed in the above section are the “Journal logs”.

The “Journald” is a system program from the systemd tool that collects data from multiple logs in a binary format. It works the same way as syslog but gives a more efficient way to manage logs.

The Linux system has an effective tool termed “journalctl” that helps the user read and communicate with the “journal logs”. This utility is a standard way to display log messages provided by journald and monitor them.

The syntax of the “journalctl” command is:

journalctl [options…] [matches…]

How to Use “journalctl” Command?

Execute the “journalctl” command without any argument in a command-line to display all records of journal logs from the oldest entries:

The displayed output is listed in less which means you can use directional keys to search and read log entries.

How to Use “journalctl” Command Options?

The “journalctl” command has several options to display journal logs. These are:

Use the “–no-page” to get logs in the terminal instead of to show with “less” features:

$ sudo journalctl –no-page

How to Use Linux Journalctl Command? 1620431792 10 How to Use Linux Journalctl Command

It will display the following result:

How to Use Linux Journalctl Command? 1620431793 853 How to Use Linux Journalctl Command

To display all log fields whether they are unprintable, use the “–all” option in the command-line prompt:

How to Use Linux Journalctl Command? 1620431794 251 How to Use Linux Journalctl Command

To limit the output lines of journalctl log, run the “-n” flag with the number of lines you want to display:

$ sudo journalctl –n 15

How to Use Linux Journalctl Command? 1620431794 457 How to Use Linux Journalctl Command

Run the “-f” flag to display the journal log in real-time:

How to Use Linux Journalctl Command? 1620431795 196 How to Use Linux Journalctl Command

To display the record of kernel logs, execute the “-k” flag:

How to Use Linux Journalctl Command? 1620431796 862 How to Use Linux Journalctl Command

To display the list of boot sessions that include the boot time, run the “–list-boot” option of the “journalctl” command:

$ sudo journalctl –list-boot

How to Use Linux Journalctl Command? 1620431796 951 How to Use Linux Journalctl Command

Whenever you run the “journalctl” command, it will display the journal logs in local time by default, but if you want to specify the logs in UTC, do it through the given command:

How to Use Linux Journalctl Command? 1620431797 960 How to Use Linux Journalctl Command

The “journalctl” command allows the user to get the record of logs of a certain period.

For example, to get the log record of yesterday, type:

$ sudo journalctl –since “yesterday”

How to Use Linux Journalctl Command? 1620431797 809 How to Use Linux Journalctl Command

Or if you want to check the record of the last 2 hours, use:

$ sudo journalctl –since2 hours ago”

How to Use Linux Journalctl Command? 1620431798 142 How to Use Linux Journalctl Command

The “-r” or “–reverse” option is used to display the logs with the newest entries first in command-line:

How to Use Linux Journalctl Command? 1620431799 842 How to Use Linux Journalctl Command

Execute the “-q” or “–quiet” option if you don’t want to display an irrelevant message like warning or info:

$ sudo journalctl –quiet

How to Use Linux Journalctl Command? 1620431799 375 How to Use Linux Journalctl Command

To display the help message of the “journalctl” command and all of its options, use the “–help” option:

$ sudo journalctl –-help

How to Use Linux Journalctl Command? 1620431800 583 How to Use Linux Journalctl Command

Check the version of the “journalctl” command using the “–version” option:

How to Use Linux Journalctl Command? 1620431801 674 How to Use Linux Journalctl Command

Conclusion:

In this brief tutorial, we have seen how the “journalctl” command and its options work. The “journalctl” command is a command-line utility used to display the record of journal logs. The Journal logs are recorded in a binary format that can be accessed anytime. Using the “journalctl” command, one can manage and analyze the record of all logs.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More