wiki/cli.journalctl.html

29 lines
16 KiB
HTML
Raw Permalink Normal View History

2022-07-29 15:41:17 +00:00
<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width"/><meta charSet="utf-8"/><title>Command line: journalctl</title><script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script><script id="MathJax-script" async="" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script><script type="text/x-mathjax-config">
MathJax = {
tex: {
inlineMath: [ [&#x27;$&#x27;,&#x27;$&#x27;], [&#x27;\(&#x27;,&#x27;\)&#x27;] ],
displayMath: [ [&#x27;$$&#x27;,&#x27;$$&#x27;], [&#x27;[&#x27;,&#x27;]&#x27;] ]
},
options = {
processHtmlClass = &quot;math&quot;
}
}
</script><meta name="next-head-count" content="6"/><link rel="preload" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" as="style"/><link rel="stylesheet" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" data-n-g=""/><noscript data-n-css=""></noscript><link rel="preload" href="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" as="script"/></head><body><div id="__next"><main><h1>Command line: journalctl</h1><section class="post-metadata"><span>Date: <!-- -->2021-05-20 23:07:39 +08:00</span><span>Date modified: <!-- -->2021-09-01 22:39:16 +08:00</span></section><nav class="toc"><ol class="toc-level toc-level-1"><li class="toc-item toc-item-h1"><a href="/wiki/cli.journalctl#options" class="toc-link toc-link-h1">Options</a></li><li class="toc-item toc-item-h1"><a href="/wiki/cli.journalctl#examples" class="toc-link toc-link-h1">Examples</a><ol class="toc-level toc-level-2"><li class="toc-item toc-item-h2"><a href="/wiki/cli.journalctl#watch-the-logs-from-a-specific-unit-at-boot-time" class="toc-link toc-link-h2">Watch the logs from a specific unit at boot time</a></li><li class="toc-item toc-item-h2"><a href="/wiki/cli.journalctl#delete-the-logs-older-than-a-month" class="toc-link toc-link-h2">Delete the logs older than a month</a></li><li class="toc-item toc-item-h2"><a href="/wiki/cli.journalctl#view-the-latest-logs-with-helpful-messages" class="toc-link toc-link-h2">View the latest logs with helpful messages</a></li><li class="toc-item toc-item-h2"><a href="/wiki/cli.journalctl#get-the-logs-of-a-service-unit-from-2-boots-ago" class="toc-link toc-link-h2">Get the logs of a service unit from 2 boots ago</a></li></ol></li></ol></nav><p>The logging daemon of systemd (see <a href="/wiki/linux.systemd.journal">systemd-journald</a>).
Not only it can view your logs, you can ask to view specific logs and delete some of them.
</p><p>For more information, see <code class="inline-verbatim">journalctl.1</code> manual page.
</p><h1 id="options">Options</h1><ul><li><p><code class="inline-verbatim">-b, --boot [ID][+OFFSET]</code> shows the logs starting from given boot time (or current boot if empty).
</p></li><li><p><code class="inline-verbatim">-e, --pager-end</code> to go to the end of the logs.
</p></li><li><p><code class="inline-verbatim">-f, --follow</code> watches the logs.
</p></li><li><p><code class="inline-verbatim">-k, --dmesg</code> prints the logs from the kernel.
</p></li><li><p><code class="inline-verbatim">--list-boots</code> prints a list of boots useful for knowing the boot logs from <code class="inline-verbatim">-b</code>.
</p></li><li><p><code class="inline-verbatim">--user-unit</code> shows logs from a user unit.
</p></li><li><p><code class="inline-verbatim">-u, --unit [UNIT]</code> shows the logs of a system unit.
</p></li><li><p><code class="inline-verbatim">--vacuum-time [TIMESPAN]</code> deletes logs older than the specified timespan <!-- -->.
</p></li><li><p><code class="inline-verbatim">-x, --catalog</code> prints helpful messages such as the documentation URIs.
</p></li></ul><h1 id="examples">Examples</h1><p>This tool is already comprehensive.
Needs a comprehensive database of examples to fight against this scope.
</p><h2 id="watch-the-logs-from-a-specific-unit-at-boot-time">Watch the logs from a specific unit at boot time</h2><pre class="src-block"><code>journalctl --user-unit borgbackup.service -fb
</code></pre><h2 id="delete-the-logs-older-than-a-month">Delete the logs older than a month</h2><pre class="src-block"><code>journalctl --vacuum-time=1m
</code></pre><h2 id="view-the-latest-logs-with-helpful-messages">View the latest logs with helpful messages</h2><pre class="src-block"><code>journalctl -xe
</code></pre><h2 id="get-the-logs-of-a-service-unit-from-2-boots-ago">Get the logs of a service unit from 2 boots ago</h2><pre class="src-block"><code>journalctl --boot -2 --user-unit borgbackup@personal-drive.service
</code></pre><section><h2>Backlinks</h2><ul><li><a href="/wiki/linux.systemd.journal">systemd-journald</a></li></ul></section></main></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"metadata":{"date":"\"2021-05-20 23:07:39 +08:00\"","date_modified":"\"2021-09-01 22:39:16 +08:00\"","language":"en","source":""},"title":"Command line: journalctl","hast":{"type":"root","children":[{"type":"element","tagName":"nav","properties":{"className":"toc"},"children":[{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-1"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"options"},"children":[{"type":"text","value":"Options"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.journalctl#options"},"children":[{"type":"text","value":"Options"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"examples"},"children":[{"type":"text","value":"Examples"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.journalctl#examples"},"children":[{"type":"text","value":"Examples"}]},{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-2"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"watch-the-logs-from-a-specific-unit-at-boot-time"},"children":[{"type":"text","value":"Watch the logs from a specific unit at boot time"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.journalctl#watch-the-logs-from-a-specific-unit-at-boot-time"},"children":[{"type":"text","value":"Watch the logs from a specific unit at boot time"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"delete-the-logs-older-than-a-month"},"children":[{"type":"text","value":"Delete the logs older than a month"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.journalctl#delete-the-logs-older-than-a-month"},"children":[{"type":"text","value":"Delete the logs older than a month"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"view-the-latest-logs-with-helpful-messages"},"children":[{"type":"text","value":"View the latest logs with helpful messages"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.journalctl#view-the-latest-logs-with-helpful-messages"},"children":[{"type":"text","value":"View the latest logs with helpful messages"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"get-the-logs-of-a-service-unit-from-2-boots-ago"},"children":[{"type":"text","value":"Get the logs of a service unit from 2 boots ago"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.journalctl#get-the-logs-of-a-service-unit-from-2-boots-ago"},"children":[{"type":"text","value":"Get the logs of a service unit from 2 boots ago"}]}]}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The logging daemon of systemd (see "},{"type":"element","tagName":"a","properties":{"href":"/linux.systemd.journal"},"children":[{"type":"text","value":"systemd-journald"}]},{"type":"text","value":").\nNot only it can view your logs, you can ask to view specific logs and delete some of them.\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For m