Ravindra BagaleCourses & study guides मराठी Track your progress

AWS Cloud

Linux Logs Explained: journalctl, /var/log, rsyslog and logrotate with Examples

Logs are the diary of your server. When something breaks at 3 a.m., logs tell you what happened and when. Linux keeps logs in two places: the systemd journal (read with journalctl) and text files in /var/log (written by rsyslog). logrotate stops those files from filling the disk. This chapter teaches each command and option one by one.

In this chapter

  • Know the main files in /var/log
  • Filter the journal by unit, time, boot and priority
  • Follow logs live and print JSON
  • Keep the journal persistent and small
  • Write rsyslog rules and send logs to a server
  • Rotate logs with logrotate

1. An everyday example: the shop's bill book

A kirana shop in Kothrud writes every sale in a bill book. When the book is full, the owner ties it, labels it with the month and puts it on a shelf. After a year, he throws out the oldest books. If a customer complains, he opens the right book and finds the right date.

Bill book = a log file. Writing each sale = a program writing log lines. Tying and labelling a full book = logrotate. Throwing the oldest = rotate 7. Finding the right date = journalctl --since or grep.

How one log line travelsA program writes to stdout, syslog() or /dev/logsystemd-journald catches it and stores it with metadatarsyslog reads from the journal and writes text files in /var/logOptionally rsyslog forwards it to a central log serverlogrotate renames and compresses old files every dayYou read it with journalctl, less, tail or grep
With a conventional rsyslog setup, look for /var/log/syslog on Ubuntu or /var/log/messages on RHEL-family systems. A journal-only install may have neither file.

2. /var/log: the main log files

Many tools and older apps write plain text files. You must know which file to open.

/var/log holds text logs. Most need sudo to read. Use tail -n, tail -f, less +F and grep on them.

FileWhat is inside
/var/log/messages or syslogGeneral system messages
/var/log/secure or auth.logLogins, sudo, SSH
/var/log/dmesg, kern.logKernel messages
/var/log/croncron job runs
/var/log/nginx/Web access and error logs
/var/log/dnf.log or apt/history.logPackage installs
  1. See the files.
ls -lh /var/log | head -5

Output:

-rw-------. 1 root root  1.2M Oct 25 12:10 messages
-rw-------. 1 root root  210K Oct 25 12:09 secure
-rw-------. 1 root root   18K Oct 25 12:00 cron
drwxr-xr-x. 2 root root  4.0K Oct 25 00:00 nginx

Mostly root-only.

  1. Last 5 SSH login lines.
sudo tail -n 5 /var/log/secure

Output:

Oct 25 12:09:41 web1 sshd[5120]: Accepted publickey for ec2-user from 49.36.1.10 port 51022 ssh2

Who logged in, from where.

  1. Failed logins.
sudo grep 'Failed password' /var/log/secure | tail -n 3

Output:

Oct 25 03:12:07 web1 sshd[901]: Failed password for root from 185.22.1.9 port 4410 ssh2

Brute force attempts.

3. journalctl: read the whole journal

Every systemd service sends its output to the journal. One command reads all of it.

journalctl alone shows all entries oldest first in a pager. -r = newest first. -n 20 = last 20 lines. --no-pager = print directly. -e = jump to the end. Use sudo or join group systemd-journal (or adm) to see all.

  1. Last 3 entries.
sudo journalctl -n 3 --no-pager

Output:

Oct 25 12:10:01 web1 CROND[5201]: (root) CMD (/usr/local/bin/backup.sh)
Oct 25 12:10:02 web1 systemd[1]: Started Session 41 of User ec2-user.
Oct 25 12:10:05 web1 sudo[5222]: ec2-user : COMMAND=/bin/journalctl -n 3

Time, host, program[PID], message.

  1. Newest first.
sudo journalctl -r -n 2 --no-pager

Output:

Oct 25 12:10:05 web1 sudo[5222]: ...
Oct 25 12:10:02 web1 systemd[1]: ...

Reverse order.

4. journalctl -u: one service

A web request might fail once while the machine keeps working. To find the right log, identify the unit that handled it and write down the approximate time. Use journalctl -u nginx --since "10 minutes ago" on the lab if nginx is the service you tested. Sort the lines in your head by what they tell you: the timestamp places the event, the unit or process identifies the source, and the message explains the result. A syntax error from an earlier start is evidence about that start. Make a fresh request to see whether it still happens.

You care about one broken service, not the whole system.

-u NAME shows only that unit. Repeat -u for several. Mix with -n, -f, --since. Works with timers and other units too.

  1. Last 20 lines of the API.
journalctl -u shop-api -n 20 --no-pager

Output:

Oct 25 12:01:44 web1 node[4410]: Error: cannot connect to DB at 10.0.0.9:5432
Oct 25 12:01:44 web1 systemd[1]: shop-api.service: Main process exited, code=exited, status=1/FAILURE

The app error plus systemd's view.

  1. Two units together.
journalctl -u nginx -u php-fpm -n 10 --no-pager

Output:

(lines from both, mixed by time)

Good for request chains.

5. journalctl -f: follow live

When you test a fix, you want to see new log lines appear as they happen.

-f keeps printing new lines, like tail -f. Ctrl+C to stop. Combine: journalctl -fu NAME. tail -F FILE does the same for text files and survives rotation.

  1. Watch the API while you restart it.
journalctl -fu shop-api

Output:

Oct 25 12:20:11 web1 systemd[1]: Started Shop API.
Oct 25 12:20:12 web1 node[5301]: listening on :3000

Open in a second terminal.

  1. Follow nginx errors.
sudo tail -F /var/log/nginx/error.log

Output:

2026/10/25 12:21:03 [error] 1013#0: *77 connect() failed (111: Connection refused) while connecting to upstream

-F re-opens after rotation.

6. --since and --until: time windows

An alert says 'errors at 2:15 p.m.'. You want only that window.

--since and --until take '2026-10-25 14:00', 'today', 'yesterday', '1 hour ago', '-30m'. Times are local unless you add UTC.

  1. The incident window.
journalctl -u shop-api --since '2026-10-25 14:10' --until '2026-10-25 14:20' --no-pager | wc -l

Output:

42

42 lines to read, not 40,000.

  1. Last 30 minutes.
journalctl --since '30 min ago' -p err --no-pager

Output:

Oct 25 12:01:44 web1 node[4410]: Error: cannot connect to DB

Fast health look.

7. -p: filter by priority

Most lines are info. In an incident you want errors only.

Levels: 0 emerg, 1 alert, 2 crit, 3 err, 4 warning, 5 notice, 6 info, 7 debug. -p err shows err and more serious. -p warning..err gives a range.

  1. Errors this boot.
journalctl -b -p err --no-pager | head -3

Output:

Oct 25 09:10:05 web1 kernel: xfs: Ending clean mount
Oct 25 12:01:44 web1 node[4410]: Error: cannot connect to DB

Short list to fix.

  1. Warnings only.
journalctl -p warning..warning --since today --no-pager | wc -l

Output:

17

Exactly one level.

8. -b and --list-boots: logs per boot

After a reboot, -b selects the current boot. If the incident triggered the reboot, use --list-boots to see the stored boot IDs and times and check the previous one with -b -1. In a persistent journal, you can compare the last lines of the old boot with the startup of the new boot. If the previous boot is absent, check the storage setting and whether the journal kept that time range. A missing log window tells you what evidence is available.

After a crash and reboot, you need the logs from before the reboot.

-b = this boot. -b -1 = the previous boot. --list-boots shows all saved boots. Needs a persistent journal to keep old boots.

  1. List boots.
journalctl --list-boots --no-pager

Output:

-1 6a1f... Sat 2026-10-24 08:01:10 IST—Sun 2026-10-25 09:09:50 IST
 0 9c2e... Sun 2026-10-25 09:10:00 IST—Sun 2026-10-25 12:22:00 IST

Two boots saved.

  1. End of the previous boot.
journalctl -b -1 -n 5 --no-pager

Output:

Oct 25 09:09:48 web1 kernel: Out of memory: Killed process 4410 (node)

OOM killed the app before reboot.

9. -k and dmesg: kernel messages

Disk errors, out-of-memory kills and USB problems are reported by the kernel.

journalctl -k shows kernel messages for this boot. dmesg -T prints the kernel ring buffer with human times. dmesg -w follows. Search for 'Out of memory', 'I/O error'.

  1. Look for OOM kills.
sudo dmesg -T | grep -i 'out of memory'

Output:

[Sun Oct 25 09:09:48 2026] Out of memory: Killed process 4410 (node) total-vm:2.1GB

The kernel killed the app.

  1. Kernel errors only.
journalctl -k -p err --no-pager

Output:

Oct 25 09:10:03 web1 kernel: nvme1n1: I/O error, dev nvme1n1, sector 2048

A disk problem.

10. -o: output formats, json and grep

Sometimes you need exact fields for a script or a log tool, or just the message.

-o short (default), -o short-iso (ISO times), -o cat (message only), -o json or json-pretty (all fields). -g PATTERN (or --grep) searches messages. _PID=, _UID=, SYSLOG_IDENTIFIER= filter by field.

  1. JSON for one line.
journalctl -u shop-api -n 1 -o json-pretty --no-pager | head -5

Output:

{
	"_PID" : "4410",
	"PRIORITY" : "3",
	"MESSAGE" : "Error: cannot connect to DB at 10.0.0.9:5432",

Every field is there.

  1. Search the message.
journalctl -u shop-api -g 'timeout' --since today --no-pager | wc -l

Output:

12

12 timeouts today.

  1. Messages only.
journalctl -u shop-api -n 2 -o cat --no-pager

Output:

listening on :3000
GET /health 200

No dates, easy to read.

11. Persistent journal, --disk-usage and --vacuum

On some systems the journal lives in RAM and vanishes at reboot. On others it slowly fills the disk.

If /var/log/journal exists, logs survive reboot (Storage=persistent in /etc/systemd/journald.conf). --disk-usage shows size. --vacuum-size=500M or --vacuum-time=14d deletes old files. SystemMaxUse=1G sets a limit.

  1. Size now.
journalctl --disk-usage

Output:

Archived and active journals take up 2.3G in the file system.

Too big for a small disk.

  1. Trim to 500 MB.
sudo journalctl --vacuum-size=500M

Output:

Vacuuming done, freed 1.8G of archived journals from /var/log/journal/9c2e....

Old archives removed.

  1. Make it persistent and capped.
sudo mkdir -p /var/log/journal && printf '[Journal]\nStorage=persistent\nSystemMaxUse=1G\n' | sudo tee /etc/systemd/journald.conf.d/size.conf && sudo systemctl restart systemd-journald

Output:

[Journal]
Storage=persistent
SystemMaxUse=1G

Survives reboot, never over 1 GB.

12. logger: write your own log lines

Try one known message before diagnosing someone else’s logs. Write logger -t classroom "report lab started" and search with journalctl -t classroom --since "5 minutes ago". The tag is the label you assigned. Check the time and exact text returned. Write a second message for the end of the run. This gives you a small pair of events to find later and shows how an application can leave evidence even when nobody is watching its terminal.

Your shell scripts should leave a record in the same place as everything else.

logger 'message' writes to syslog/journal. -t TAG sets the program name. -p user.err sets priority. Then search with journalctl -t TAG.

  1. Log from a backup script.
logger -t backup -p user.err 'backup failed: disk full'

Output:

(no output)

It is now in the journal and /var/log/messages.

  1. Find it.
journalctl -t backup -n 1 --no-pager

Output:

Oct 25 12:30:00 web1 backup[5410]: backup failed: disk full

Tag makes it easy to find.

13. rsyslog: rules and remote logging

You may want app logs in their own file, or all servers' logs on one central box that survives if a server dies.

Config is /etc/rsyslog.conf plus /etc/rsyslog.d/*.conf. A rule is 'facility.priority destination'. Example: local0.* /var/log/myapp.log. @host:514 sends UDP, @@host:514 sends TCP. Check with rsyslogd -N1, then restart rsyslog.

  1. Send local0 to its own file.
echo 'local0.*  /var/log/myapp.log' | sudo tee /etc/rsyslog.d/30-myapp.conf && sudo rsyslogd -N1 && sudo systemctl restart rsyslog

Output:

rsyslogd: End of config validation run. Bye.

Config is valid.

  1. Test it.
logger -p local0.info 'order 1001 placed' && sudo tail -n1 /var/log/myapp.log

Output:

Oct 25 12:35:10 web1 ec2-user: order 1001 placed

The rule works.

  1. Forward everything to a log server by TCP.
echo '*.* @@10.0.0.50:514' | sudo tee /etc/rsyslog.d/90-forward.conf && sudo systemctl restart rsyslog

Output:

*.* @@10.0.0.50:514

Two @ means TCP.

14. logrotate: stop logs from filling the disk

An app log can grow to 50 GB and stop the whole server. logrotate keeps only what you need.

Main config /etc/logrotate.conf, app configs in /etc/logrotate.d/. Common options: daily/weekly, rotate 7, compress, delaycompress, missingok, notifempty, maxsize 100M, create 0640 user group, copytruncate (for apps that cannot reopen), postrotate ... endscript. It runs daily from a timer or cron. -d = dry run, -f = force now.

OptionMeaning
rotate 7Keep 7 old files
compressgzip old files
delaycompressCompress from the second old file
missingokNo error if the log is missing
notifemptySkip empty logs
copytruncateCopy then empty in place
  1. Write a rule for the app.
sudo tee /etc/logrotate.d/shop <<'X'
/var/log/shop/*.log {
    daily
    rotate 7
    compress
    delaycompress
    missingok
    notifempty
    create 0640 shop shop
    postrotate
        systemctl reload shop-api >/dev/null 2>&1 || true
    endscript
}
X

Output:

(file text)

One week of logs, compressed.

  1. Dry run.
sudo logrotate -d /etc/logrotate.d/shop

Output:

rotating pattern: /var/log/shop/*.log  after 1 days (7 rotations)
considering log /var/log/shop/api.log

Nothing changes; it only explains.

  1. Force now and check.
sudo logrotate -f /etc/logrotate.d/shop && ls /var/log/shop

Output:

api.log  api.log.1

Next run makes api.log.2.gz.

15. Real examples from many industries

The same Linux skill shows up in every kind of company. Seeing it in many places helps you remember it.

Each row is a made-up team. It shows who uses this and how.

Team and cityHow they use itCommand
Pooja, insurance, PuneFinds failed logins in auth logs every morninggrep 'Failed password' /var/log/secure
Liam, streaming, DublinFollows a service live during deploysjournalctl -fu player-api
Fatima, telecom, CairoShips all server logs to a central box*.* @@logs.internal:514
Chen, factory sensors, ShenzhenCaps journal size on small devicesjournalctl --vacuum-size=200M
Ana, retail, São PauloRotates huge app logs dailylogrotate -f /etc/logrotate.d/pos
Vikram, hospital, NagpurReads logs from before a crash rebootjournalctl -b -1 -p err

16. Common errors and how to fix them

Everyone hits these errors. Knowing the cause saves hours.

Read the exact message first. Then match it to a row below.

Error you seeWhy it happensHow to fix
No journal files were found.Not persistent and nothing for that boot, or no permissionUse sudo; create /var/log/journal for future boots.
sudo mkdir -p /var/log/journal
Hint: You are currently not seeing messages from other users and the system.Your user is not in systemd-journal/admUse sudo or add the group.
sudo usermod -aG systemd-journal $USER
Failed to parse timestamp: 2pmjournalctl does not know that formatUse 'YYYY-MM-DD HH:MM' or '1 hour ago'.
journalctl --since '2026-10-25 14:00'
Data from the specified boot (-1) is not availableJournal not persistentEnable persistent storage.
sudo mkdir -p /var/log/journal
tail: cannot open '/var/log/secure' for reading: Permission deniedRoot-only fileUse sudo.
sudo tail /var/log/secure
No space left on device (from huge logs)Logs never rotatedFind big files, rotate and vacuum.
sudo du -sh /var/log/* | sort -h | tail
error: skipping "/var/log/shop/api.log" because parent directory has insecure permissionsFolder writable by group/othersAdd a su line or fix permissions.
su shop shop
rsyslogd: error during parsing file /etc/rsyslog.d/30-myapp.confTypo in a ruleValidate before restart.
sudo rsyslogd -N1
Disk still full after deleting a logApp still holds the deleted file openRestart the app or truncate instead of delete.
sudo lsof +L1
Logs stop after rotationApp writes to the old renamed fileReload in postrotate or use copytruncate.
copytruncate

17. Troubleshooting step by step

When you cannot find the log you need, check where the program writes, then filter down.

Go top to bottom. Stop at the first step that shows the problem.

  1. Is it a systemd service? Read its unit logs.
journalctl -u shop-api -n 50 --no-pager
  1. Find files it writes.
sudo lsof -p $(systemctl show -p MainPID --value shop-api) | grep log
  1. Narrow by time and priority.
journalctl --since '1 hour ago' -p warning --no-pager
  1. Check the kernel side.
journalctl -k -p err --no-pager
  1. Check disk use of logs.
journalctl --disk-usage; sudo du -sh /var/log
  1. Test rotation config.
sudo logrotate -d /etc/logrotate.conf

18. Lab 1: Investigate an incident with journalctl

Create log lines with logger, then find them by tag, priority and time, and print JSON.

A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).

  1. Make some noise.
for i in 1 2 3; do logger -t lab -p user.info "order $i ok"; done; logger -t lab -p user.err 'payment gateway timeout'

Output:

(no output)
  1. By tag.
journalctl -t lab --no-pager -o cat

Output:

order 1 ok
order 2 ok
order 3 ok
payment gateway timeout
  1. Errors only.
journalctl -t lab -p err --no-pager -o cat

Output:

payment gateway timeout
  1. Last 10 minutes.
journalctl -t lab --since '10 min ago' --no-pager | wc -l

Output:

4
  1. JSON fields.
journalctl -t lab -p err -o json-pretty --no-pager | grep -E 'PRIORITY|MESSAGE'

Output:

	"PRIORITY" : "3",
	"MESSAGE" : "payment gateway timeout",

19. Lab 2: Own app log file with rsyslog and logrotate

Route local1 to /var/log/lab.log and rotate it daily keeping 3 copies.

A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).

  1. rsyslog rule.
echo 'local1.* /var/log/lab.log' | sudo tee /etc/rsyslog.d/40-lab.conf && sudo rsyslogd -N1 && sudo systemctl restart rsyslog

Output:

rsyslogd: End of config validation run. Bye.
  1. Write and read.
logger -p local1.info 'lab line' && sudo tail -n1 /var/log/lab.log

Output:

Oct 25 12:40:00 web1 ec2-user: lab line
  1. Rotate rule.
printf '/var/log/lab.log {\n daily\n rotate 3\n compress\n missingok\n notifempty\n}\n' | sudo tee /etc/logrotate.d/lab

Output:

/var/log/lab.log {
  1. Force and look.
sudo logrotate -f /etc/logrotate.d/lab && ls /var/log/lab.log*

Output:

/var/log/lab.log.1.gz
  1. Clean up.
sudo rm /etc/rsyslog.d/40-lab.conf /etc/logrotate.d/lab && sudo systemctl restart rsyslog

Output:

(no output)

Ravindra Bagale's Tip

In an incident, start with three filters: -u for the service, --since for the time, -p err for the level. Most problems show up in under 20 lines.

20. Frequently asked questions

Q. journalctl or /var/log?

Both. journalctl has every systemd service; some apps only write files in /var/log.

Q. Why do my old logs disappear after reboot?

The journal is volatile. Create /var/log/journal.

Q. How long are logs kept?

journald by size limits; files by logrotate rotate count.

Q. Is it safe to delete a log file?

Better to truncate with : > file, or rotate. Deleting an open file does not free space.

Q. What is a facility?

A category like auth, cron, daemon, local0-7 used by rsyslog rules.

Q. When does logrotate run?

Daily via logrotate.timer or /etc/cron.daily.

Q. copytruncate or postrotate reload?

Reload is cleaner; copytruncate may lose a few lines.

Q. Can I see logs in UTC?

journalctl --utc.

21. Interview questions and answers

Beginner level

Q. How do you see logs of one service?

journalctl -u NAME.

Q. How do you follow logs live?

journalctl -f or tail -f FILE.

Q. Where are SSH login logs?

/var/log/secure or /var/log/auth.log.

Q. What does logrotate do?

Renames, compresses and deletes old logs on schedule.

Mid level level

Q. Logs from the previous boot?

journalctl -b -1, needs persistent journal.

Q. Only errors in the last hour?

journalctl --since '1 hour ago' -p err.

Q. Shrink the journal?

journalctl --vacuum-size or --vacuum-time; SystemMaxUse.

Q. @ vs @@ in rsyslog?

UDP vs TCP forwarding.

Senior level

Q. Disk full but du shows small /var/log. Why?

Deleted files still open; find with lsof +L1, restart the holder.

Q. Design central logging for 200 servers.

rsyslog/journald forward over TCP+TLS or an agent to a central store, with retention, indexing and alerts.

Q. Why structured (JSON) logs?

Machines can filter fields exactly; journald keeps fields; tools index them.

Q. How do you avoid losing logs during rotation?

Reload/HUP the app in postrotate; avoid copytruncate for busy logs.

Try at home

  1. Create a script that writes 'hello' with logger -t home every run. Run it 5 times and count lines with journalctl -t home.
  2. Check journalctl --disk-usage on your machine. Write a journald.conf.d file that caps it at 300M.

Practise this chapter

Interview questions and answers

A service failed before a reboot. What logs would you look for first?

List stored boots with journalctl --list-boots. If the previous boot is present, use journalctl -b -1 with the unit and time filter. If it is absent, check journal storage and retention. Use the failure time to separate the old failure from the current startup.

Check your understanding

Choose an answer, then compare your reasoning with the explanation.

0 of 3 answered correctly
1. Which journal query narrows records to one named systemd service?

Answer and explanation

B. journalctl -u followed by the service name

The unit filter selects that service. Kernel output and disk-usage reports answer different questions.

2. Which journal option selects the previous boot when it is retained?

Answer and explanation

C. -b -1

The negative boot offset selects an earlier boot. A plain -b selects the current one and -n limits line count.

3. After running logger -t classroom, what makes a good verification?

Answer and explanation

B. Find the message with the classroom tag and matching time

The tag identifies the sample source. Matching message and time prove the learner can later find the evidence.

Practice Tasks

Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.

About this scenario

Vidarbha Cotton Mills is a textiles business in Nagpur. Ganesh Wankhede looks after its IT and cloud work. They count money in INR and run their AWS resources in the ap-south-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 16

Easy Logs of one service

Logs tell you what went wrong.

Show journal logs for nginx.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Live logs

Logs tell you what went wrong.

Follow sshd logs live.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Last 50 lines

Logs tell you what went wrong.

Show the last 50 journal lines.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Journal size

Logs tell you what went wrong.

Check how much disk the journal uses.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Write a log line

Logs tell you what went wrong.

Write "backup done" to the system log with tag backup.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Classic log file

Logs tell you what went wrong.

Follow /var/log/messages live.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium This boot

Logs tell you what went wrong.

Show logs only from the current boot.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Previous boot

Logs tell you what went wrong.

Show logs from the previous boot.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Only errors

Logs tell you what went wrong.

Show only error priority and worse.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Since a time

Logs tell you what went wrong.

Show logs since one hour ago.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Kernel messages

Logs tell you what went wrong.

Show only kernel messages from the journal.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Restart rsyslog

Logs tell you what went wrong.

Restart rsyslog after editing its config.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Shrink the journal

Logs tell you what went wrong.

Reduce journal to 500M.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard JSON output

Logs tell you what went wrong.

Show nginx logs as one JSON per line.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Test logrotate

Logs tell you what went wrong.

Dry-run the nginx logrotate config.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Force rotation

Logs tell you what went wrong.

Force logrotate to rotate nginx logs now.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

In short

  1. /var/log holds text logs; journalctl reads the journal.
  2. -u, -f, --since, -p and -b are your main filters.
  3. -k and dmesg for kernel, -o json for fields.
  4. Persistent journal + vacuum keep history and disk safe.
  5. logger writes, rsyslog routes and forwards.
  6. logrotate rotates, compresses and deletes old logs.

Revision, comparison and interview cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

journalctl filters. Find the error fast. -u unit, -f follow. -p err, --since, -b. Errors of one service today.
Revision card: journalctl filters · Download PNG · Open card page
logrotate safely. Stop logs filling the disk. daily, rotate 7, compress. Dry-run before trusting. Test a config.
Revision card: logrotate safely · Download PNG · Open card page
journalctl vs /var/log files. Binary indexed journal. / Plain text via rsyslog.
Comparison: journalctl vs /var/log files · Download PNG · Open card page
logrotate vs journalctl --vacuum. Text log files. / The systemd journal.
Comparison: logrotate vs journalctl --vacuum · Download PNG · Open card page
journald vs rsyslog?. journald: binary, indexed. rsyslog: text files, remote. Both often run together.
Interview card: journald vs rsyslog? · Download PNG · Open card page
Logs filled the disk?. Find the big files. Vacuum journal, fix rotation. Shrink the journal.
Interview card: Logs filled the disk? · Download PNG · Open card page
Why copytruncate?. App keeps the file open. Copy then empty it in place. Or signal the app to reopen.
Interview card: Why copytruncate? · Download PNG · Open card page
Keep logs after reboot?. Default may be in /run. Create /var/log/journal. Restart journald.
Interview card: Keep logs after reboot? · Download PNG · Open card page

More cards: Ravi Sir's Cards.