How to use the journalctl command in Linux?
The journalctl command in Linux is used to view and manage system logs, tracking and displaying system log messages.
Here are some common usages of the journalctl command:
- View all logs:
- log viewer
- View the latest journal entries:
- show the last entries in the system journal
- View logs for a specific number of lines:
- journalctl -n
- View logs for a specific unit (such as a service unit):
- Show logs for a specific unit with journalctl.
- View logs within a specific time range.
- Display logs since “
” until “ ” using journalctl. - real-time tracking of logs
- Display live log messages in real-time.
- View logs of a specific priority:
- View journal entries with specified priority level in the journal.
- View the logs of a specific user:
- Show logs for the user with the specified ID.
- View the logs of a specific process.
- journalctl _PID=
- View logs for specified keywords.
- journalctl _COMM=
- View the log of a specific file.
- View kernel messages in real-time from the current boot using journalctl and filter for messages containing the specified file name.
In addition to the commonly used options mentioned above, the journalctl command also supports more choices and filters, which can be used according to specific needs. You can refer to the complete help documentation by using the man journalctl command.