Since @Julien's answer no longer appears to work on my system (Debian 11), I've finally given in and hijacked systemctl on my system:
systemctl() {
if [[ "${1-}" == "log" ]]; then
/usr/bin/journalctl -u "${@:2}";
else /usr/bin/systemctl "$@";
fi
}
Add this one-liner to your .bashrc and your systemctl will gain a new log "verb" that provides the missing functionality. No more wasting time retyping tedious commands.
As an added bonus, this method will also give you access to all the options of journalctl (provided that they're specified after the unit name):
systemctl log named.service --since=today
Edit: To address John's comment about the lack of bash-completion support and provide a more complete answer, we might as well hijack systemctl's bash completion function too:
source "/usr/share/bash-completion/completions/systemctl"
source "/usr/share/bash-completion/completions/journalctl"
_systemd_log_hijack() {
if [[ "${COMP_WORDS[1]}" == "log" ]]; then
if [[ "${COMP_CWORD}" == "2" ]]; then
COMPREPLY=( $(systemctl list-units 2>&1 | awk -c ' { print $1 }' | grep -F "${COMP_WORDS[2]}") )
elif [[ "${COMP_CWORD}" -gt "2" ]]; then
(( COMP_CWORD++ )) || true
COMP_WORDS=("journalctl" "-u" "${COMP_WORDS[2]}" "${COMP_WORDS[@]:2}")
COMP_LINE="${COMP_WORDS[*]}"
_journalctl
fi
else
_systemctl
fi
if [[ "${COMP_CWORD}" == "1" && "log" == "${COMP_WORDS[1]}"* ]]; then
COMPREPLY=("log" "${COMPREPLY[@]}")
fi
}
complete -F _systemd_log_hijack systemctl
This isn't a polished solution but it should provide usable bash completion for the non-standard log command verb.
Keep in mind that this is merely a hack to fix poorly-designed UX. The right way would be to somehow convince the SystemD project to accept a fix upsteam.
--no-pagerwill print full log, so you wont have to scroll – Dushyant Bangal May 29 '17 at 11:41-ewill start the log at the end removing the need to scroll, but without printing the entire log beforehand. – timlyo Jul 28 '17 at 14:45-fwill follow (print) updates to the log – Joe Jasinski Sep 06 '17 at 17:10--helpwill let you see all available options – Tzafrir Mar 26 '18 at 20:14journalctlto access them. – larsks Apr 11 '19 at 11:43https://www.freedesktop.org/software/systemd/man/systemd-journald.service.html– viveksinghggits Apr 11 '19 at 11:58sudo systemctl -n 99999 statusgives me that, but apparently journalctl can only filter "from boot", not "from service start". – tobixen Jun 26 '19 at 04:57--no-pagerwill allow it to be piped? (say, togrep?) – DarthCadeus Nov 07 '19 at 14:10--no-pageris not necessary when piping the output. It's only useful to disable the pager when output is to an interactive terminal.journalctldoes not use a pager when you're piping the output to something else. – larsks Nov 07 '19 at 14:12-u) and thus combine the log of multiple services. – rugk Jul 28 '20 at 12:32shift-gto jump to the end of file inlessor similar pagers. – Matthias Sep 03 '20 at 22:14-o catwill remove systemd log text processing so you can see the output as the process produced it. – fuzzyTew Jun 30 '21 at 10:11journalctl UNIT=foobar.servicethinking like me that it's the same asjournalctl -u foobar.service, because it's not! WithUNIT=sudo commands coming from a custom script are not listed; they are displayed with-u. – 4wk_ Jan 19 '22 at 16:28-- No entries --– Alecz Sep 14 '22 at 17:18