The Wayback Machine - https://web.archive.org/web/20240717024710/https://www.geeksforgeeks.org/journalctl-command-in-linux-with-examples/
Open In App

journalctl Command in Linux with Examples

Last Updated : 21 Jul, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The `journalctl` command is part of the systemd suite of utilities and is used to query and display log messages from the systemd journal. The systemd journal is a centralized logging system that collects and stores log data from various sources, including system services, kernel events, and user applications. The journalctl command provides a user-friendly interface to access and retrieve log information, allowing users to effectively monitor system activity and diagnose issues.

Syntax of the `journalctl` command in Linux

The basic syntax of the `journalctl` command is as follows:

journalctl [options] [unit]

Here,

[options] = The various command-line options available to customize the output.

[unit] = The specific system unit or log source to query. If no unit is specified, `journalctl` will display the message from all available units.

Working with journalctl command

1. To display all logs

journalctl

Display all Logs

Display all Logs

This command will display the recent log messages from all units in reverse chronological order, starting from the most recent entries.

2. Reversing the log order

To reverse the order or to display the new entries first.

journalctl -r

Reversing Logs

Reversing Logs

This command displays logs in reverse chronological order, showing the most recent entries at the top.

3. Limiting the number of log entries

If you only want to display a specific number of log entries, you can use the -n option followed by the desired number

journalctl -n 2

Limiting the number

Limiting the number

This will display just 2 log entries.

4. Filtering logs by keyword

To retrieve log entries containing a specific keyword or phrase, you can use the grep command in combination with journalctl.

journalctl | grep Centaur

Filtering Logs

Filtering Logs by keyword

This will display all the entries containing the word Centaur in them.

Advanced Usage of the journalctl Command

The journalctl command provides additional options and features to further refine log queries and retrieve specific information. Here are a few examples

1. Filtering logs by priority level

To display log entries based on their priority level, you can use the -p option followed by the desired level (e.g., emerg, alert, crit, err, warning, notice, info, or debug). For instance

journalctl -p warning

Filtering logs by priorty

Filtering logs by priorty

It displays all log entries with priority as a warning.

2. Customizing output format

You can modify the format in which log entries are displayed using the -o option. For instance, to display verbose output, use

journalctl -o verbose

customizing output

customizing output

This will display the formatted output in verbose mode.

3. Listing system boots

To view information about previous system boots, you can use the –list-boots option.

journalctl --list-boots

listning system boots

listning system boots

This command provides a list of system boots along with their boot IDs and timestamps.

4. Accessing help documentation

To access the journalctl command’s help section, you can use the –help option.

journalctl --help

Accessing Help

Accessing Help

This command displays detailed information about the command’s usage, options, and functionalities.

Conclusion

In this article we have discussed the `journalctl` command in linux which is a powerful tool for accessing and analyzing system, kernel, and journal Overall, we can say that by understanding the `journalctl` command and leveraging its capabilities, system administrators and users can give valuable insights into system activity and resolve issues effectively


Previous Article
Next Article

Similar Reads

How to Read and Edit Systemd Logs using Journalctl in linux
In the realm of Linux system administration, managing logs is an indispensable task. System logs are crucial for understanding the health, performance, and troubleshooting of a system. Systemd, the init system widely adopted by modern Linux distributions, introduced a centralized logging system called the Journal. `journalctl` is the primary tool p
6 min read
How To Use Journalctl to View and Manipulate Systemd Logs
Journalctl is a powerful command-line utility in Linux for querying and displaying logs managed by systemd-journald. It lets users access detailed information about system events, services, and processes. With journalctl, you can filter logs based on various criteria such as time range, specific units, or log levels, enabling effective troubleshoot
4 min read
Ccat – Colorize Cat Command Output command in Linux with Examples
ccat is a command-line tool for Linux and OSX, which is similar to the cat command in Linux. But the difference between cat and ccat is that the ccat shows the content of the file with the syntax highlighted. Currently, ccat supports the following programming languages. JavaScriptJavaRubyPythonGoCJSONInstallation of Ccat First, we are going to see
2 min read
How to Display Command History in Linux | history Command
The command-line interface in Linux provides powerful tools for users, and mastering command history is essential for efficient navigation and retrieval of previously executed commands. The history command is a valuable utility that allows users to view and search through their command history. In this comprehensive guide, we will explore the vario
4 min read
select command in Linux with examples
select command in Linux is used to create a numbered menu from which a user can select an option. If the user enters a valid option then it executes the set of command written in select block and then ask again to enter a number, if a wrong option is entered it does nothing. If user enters nothing and simply press 'enter' the option menu gets print
1 min read
atrm command in Linux with examples
atrm command is used to remove the specified jobs. To remove a job, its job number is passed in the command. A user can only delete jobs that belong to him. Only superuser can delete any job even if that belongs to another user. Syntax: atrm [-V] job [job...] Options: -V : Used to print the version number atrm -V job : Job number of the job which i
1 min read
comm command in Linux with examples
comm compare two sorted files line by line and write to standard output; the lines that are common and the lines that are unique. Suppose you have two lists of people and you are asked to find out the names available in one and not in the other, or even those common to both. comm is the command that will help you to achieve this. It requires two so
5 min read
cmp Command in Linux with examples
cmp command in Linux/UNIX is used to compare the two files byte by byte and helps you to find out whether the two files are identical or not. When cmp is used for comparison between two files, it reports the location of the first mismatch to the screen if difference is found and if no difference is found i.e the files compared are identical.cmp dis
5 min read
expand Command in LINUX with examples
Whenever you work with files in LINUX there can be a situation when you are stuck with a file containing many tabs and whatever you need to do with a file requires that file with no tabs but with spaces. In this situation, the task looks quite simple if you are dealing with a small file but what if the file you are dealing with is very big or you n
3 min read
df Command in Linux with examples
There might come a situation while using Linux when you want to know the amount of space consumed by a particular file system on your LINUX system or how much space is available on a particular file system. LINUX being command friendly provides a command line utility for this i.e df command that displays the amount of disk space available on the fi
8 min read