journalctl Trình tạo lệnh
Tạo các lệnh journalctl để truy vấn nhật ký systemd
Getting Started with journalctl
## What is journalctl?
`journalctl` queries the systemd journal — the centralized log store for the system and services. It is the standard way to read service logs, filter by unit, priority, boot, or time range.
## How to Use
1. **Filter**: Narrow by unit (`-u`), priority (`-p`), boot (`-b`), or kernel (`-k`). 2. **Time Window**: Use `--since` and `--until` with values like `today`, `yesterday`, or `2026-06-25 09:00:00`. 3. **Output**: Tail with `-f`, limit lines with `-n`, format with `-o`. 4. **Copy & Run**: Copy the generated command into your terminal.
Common Options
### `-u` Unit Show messages from a specific systemd unit (service), e.g. `-u nginx` or `-u ssh.service`.
### `-p` Priority Filter by syslog priority 0–7 (0 emerg, 1 alert, 2 crit, 3 err, 4 warning, 5 notice, 6 info, 7 debug). Use `-p 3` to show errors and above.
### `-b` Current boot Show messages from the current boot. Combine with an index like `-b -1` for the previous boot.
### `-k` Kernel Show only kernel messages (equivalent to `dmesg`).
### `-n` Lines Show the last N lines, e.g. `-n 100`.
### `-f` Follow Continuously print new entries as they arrive (like `tail -f`).
### `-a` Show all Show all fields, including very long ones normally truncated.
### `--no-pager` Disable the pager for piping into other commands or scripts.
### `--since` / `--until` Filter by time, e.g. `--since today`, `--since "1 hour ago"`, or `--since "2026-06-25 09:00:00"`.
### `-x` Catalog Add explanatory catalog entries for many log messages.
### `-r` Reverse Show newest entries first.
### `-o` Output format Change the output format: `cat` (message only), `short` (default), `json`, `json-pretty`, etc.
▶How do I tail a service's logs in real time?
▶How do I show only errors for a service?
▶How do I view logs since this morning?
▶How do I get the last 100 entries, newest first?
Nếu công cụ này đã giúp ích cho bạn, hãy nghĩ đến việc mua một cốc cà phê cho tôi.
Hãy mua cho tôi một cốc cà phê nhé.