tips
81 tips Journalctl
One command, setting or habit at a time about Journalctl: what it does, the line to copy and a caveat or two.
Filtering 19
-
Read the service manager's own messages about starts, stops and failures without the services' chatter.
journalctl _PID=1 -b -
See which field names exist before you write a match on the journalctl command line.
journalctl -N | sort -
Read all instances of a template service or every matching unit in one command.
journalctl -u 'php*-fpm.service' --since today -
Separate the lines a service printed with echo or print from its proper log calls.
journalctl _TRANSPORT=stdout -u myapp -
Read the logs of every process in one slice, such as one user's session.
journalctl _SYSTEMD_SLICE=user-1000.slice --since today -
Shows the log lines of only the last run of a service, or the run before it.
journalctl -u backup.service -I -
Combines two journal matches with OR instead of AND, so one command shows two sources together.
journalctl -b _SYSTEMD_UNIT=ssh.service + _COMM=sudo -
Shows only the journal entries about one device, such as a failing disk, for the current boot.
journalctl /dev/sda -
Filters the journal by a program's file path, which works when you do not know the unit name.
journalctl -b /usr/sbin/sshd -
Combining a text search with a line count prints the newest matches first, because the order flips.
journalctl -g timeout -n 5 -
Reads the journal of a running systemd container from the host by its machine name.
journalctl -M mycontainer -b -
Shows the logs of one journal namespace, or all namespaces at once with a star.
journalctl --namespace=myapp -
Shows the journal entries written by processes that run under one user ID, for example your own.
journalctl --since today _UID=$(id -u) -
Shows the logs of services that run in your own user session instead of the system.
journalctl --user -u myapp -
Selects log lines between two severity levels, such as warnings up to errors.
journalctl -b -p warning..err -
Filters the journal by program name, for example to review every sudo command.
journalctl -t sudo --since today -
Shows the logs of several services in a single time-ordered stream.
journalctl -u nginx -u mariadb --since "30 min ago" -f -
Filters journal messages with a regular expression and keeps the timestamps and paging.
journalctl -u ssh -g "failed|invalid user" --since yesterday -
Lists all unique values of a journal field, so you know what to filter on.
journalctl -F _SYSTEMD_UNIT
Paging and following 16
-
Scroll further back after jumping to the end of the journalctl pager.
journalctl -u nginx -e -n 5000 -
Make the journalctl pager wrap long lines instead of cutting them off at the screen edge.
SYSTEMD_LESS=FRXMK journalctl -u nginx -
Stores the position of the last log entry in a file so the next journalctl run only shows new lines.
journalctl -u nginx.service --cursor-file=/var/tmp/nginx.cursor -
Adds a short explanation beneath journal entries that have one in the message catalog.
journalctl -xb -p err -
Shows an opaque bookmark after the last line so a later run can continue from there.
journalctl --show-cursor -n 20 -
Remembers where the last run ended in a file, so each run prints only new entries.
journalctl --cursor-file=/var/tmp/jc.cursor -u myapp -
Prints all matching entries and then keeps following, instead of starting with the last ten lines.
journalctl -u nginx -f --no-tail -
Follows the journal and shows only new entries, without the usual last ten lines.
journalctl -u docker -f -n 0 -
Shortens log lines that do not fit the terminal width so a list stays scannable.
journalctl --no-full -u myapp -
Leaves the host name out of the short log lines to save space.
journalctl --no-hostname -u ssh -n 5 -
Prints the output directly instead of opening a pager, which suits scripts and pipes.
journalctl -u ssh --no-pager | grep -c Accepted -
Shows the oldest journal entries, which tells you how far back the history goes.
journalctl -n +20 -
Starts the pager at the last entries, limited to 1000 lines of the current boot.
journalctl -u nginx -e -
Removes journalctl's own informational lines, so only real log entries remain.
journalctl -q -b -1 -
Reverses the order so the newest journal entry is shown first.
journalctl -r -u ssh -
Shows complete log fields, including long ones and ones that normally appear as blob data.
journalctl -a -u myservice
Output formats 13
-
Get JSON records with a clear start marker, so a half written line can be skipped.
journalctl -t demoapp -n 1 -o json-seq | od -c | head -1 -
Keep the red errors and yellow warnings when journalctl output goes through grep or less.
SYSTEMD_COLORS=1 journalctl -b -p warning | less -R -
Writes journal entries with all their fields to a stream that can be stored or imported elsewhere.
journalctl -o export > journal.export -
Prints just the message text of each entry, without time stamps or host names.
journalctl -u myapp -o cat -
Limits JSON or verbose output to the fields you list, which keeps scripts small and fast.
journalctl -o json --output-fields=MESSAGE,PRIORITY -n 3 -
Prints the time since the previous entry on every line, to find long pauses and timeouts.
journalctl -b -o short-delta -u myapp -
Shows complete time stamps that you can paste straight into --since and --until.
journalctl -o short-full -u myapp -
Prints seconds since boot as the time stamp, which reads well for startup problems.
journalctl -b -o short-monotonic -
Prints the time as seconds since 1970 so a script can calculate with it.
journalctl -o short-unix -u myapp -
Prefixes each line with the full unit name, including the instance of templated services.
journalctl -o with-unit -u 'getty@*' -
Cuts every message after its first line, so long traces do not flood the screen.
journalctl --truncate-newline -u myapp -
Prints log timestamps in ISO 8601 or UTC so logs from different hosts can be compared.
journalctl -o short-iso -u ssh --since today -
Prints a full log entry with all its metadata fields, ready for scripting or filtering.
journalctl -u nginx -n 1 -o json-pretty
Storage 10
-
Stop journald from writing logs to an SD card or other fragile storage.
Storage=volatile -
Make journald delete old log files after a fixed age, whatever the disk size.
sudo mkdir -p /etc/systemd/journald.conf.d -
Archive the active journal file first so a cleanup can actually remove its data.
sudo journalctl --rotate -
Control the size of each journal file, and with it how coarse cleanups are.
sudo tee /etc/systemd/journald.conf.d/50-filesize.conf <<'EOF' -
Forces journald to write all pending log data to disk and returns when it is done.
sudo journalctl --sync -
Keeps a fixed number of archived journal files and removes the oldest ones.
sudo journalctl --vacuum-files=5 -
Removes archived journal files older than a chosen time span and reports the freed space.
sudo journalctl --vacuum-time=2weeks -
Caps the size and age of the stored journal permanently with a small config drop-in.
[Journal] -
Makes the journal survive reboots by creating the directory journald uses for disk storage.
sudo mkdir -p /var/log/journal -
Reports the total disk space used by the system journal files.
journalctl --disk-usage
Journal files 9
-
Understand the journal files with a tilde at the end and read them when needed.
ls -lh /var/log/journal/*/*.journal~ -
Make later changes to stored journal files detectable with a key you keep elsewhere.
sudo journalctl --setup-keys -
Make journald stop writing to /var so the disk can be unmounted cleanly.
sudo journalctl --relinquish-var -
Reads journal files from any directory, for example a disk taken from a machine that no longer boots.
journalctl -D /mnt/backup/var/log/journal -b -1 -
Reads the entries of specific journal files matching a glob instead of the system journal.
journalctl --file='/var/log/journal/*/system.journal' -n 20 -
Prints the header information of the journal files instead of log entries.
journalctl --header | head -20 -
Shows entries from all available journals, local and remote, in one time-ordered stream.
journalctl -m -b -
Reads the journal of another system that is mounted under a directory, such as a rescue mount.
journalctl --root=/mnt/system -b -1 -
Checks every journal file for corruption and reports PASS or FAIL for each file.
journalctl --verify
Boots and kernel 5
-
Filter kernel and udev messages to one kind of hardware, like USB or PCI.
journalctl -F _KERNEL_SUBSYSTEM -
Read the final lines before a reboot or crash to see whether it was a clean shutdown.
journalctl -b -1 -n 50 -
Follows kernel messages live, handy while you plug in or remove hardware.
journalctl -kf -
Shows kernel messages from the previous boot, which dmesg has already lost.
journalctl -k -b -1 -
Lists every boot the journal knows, with offsets you can pass to -b.
journalctl -b -2 -u nginx
Logs and diagnostics 5
-
Find out which program the kernel killed when memory ran out.
journalctl -k -g 'killed process' --since "2 days ago" -
Get a list of crashes from the journal with one fixed message ID.
journalctl MESSAGE_ID=fc2e22bc6ee647b6b90729ab34a250b1 -o short-iso -
Adds catalog explanation texts under log lines that have one, which helps with failed service starts.
journalctl -xeu nginx.service -
Stop a service's repetitive log lines from being stored in the journal at all.
sudo systemctl edit myapp.service -
Tags the log lines of several services with one field so you can read them together.
journalctl JOB=nightly-backup
Linux and shell 2
-
Read only the log lines since a service last started, without looking up the time.
journalctl -u nginx --since "$(systemctl show -p ActiveEnterTimestamp --value nginx)" -
Shrinks the systemd journal to a size you pick by deleting the oldest logs.
journalctl --disk-usage
systemd 2
-
Show only lines a service wrote itself, without the start and stop messages from systemd.
journalctl _SYSTEMD_UNIT=nginx.service -
Shows only the log lines of the last hour, or any period you give it.
journalctl --since "1 hour ago"
Nothing in this filter yet.