Back to commands

Hosting Operations

Read-only

Dry-Run Logrotate Before Touching Logs

You need to understand what logrotate would do without compressing, renaming, or truncating real logs.

Command

logrotate -d /etc/logrotate.conf 2>&1 | sed -n '/rotating pattern/p;/considering log/p;/error:/p'

Before you run this

System impact: Read-only. Low when scoped to the shown target.

When not to use it: Do not use -f unless you intentionally want to force rotation; this lesson is debug-only.

Expected output

rotating pattern and considering log lines from logrotate debug output.

System impact

Read-only. Nothing changes. The -d flag runs logrotate in debug mode and the pipe extracts useful decision lines.

May require elevated permissions on protected paths or service-owned files.

Recovery / rollback: no state is changed.

When to use it

Use before changing logrotate rules or when logs are growing and you need to see whether policies match them.

When not to use it

Do not use -f unless you intentionally want to force rotation; this lesson is debug-only.

Dry-run limitation

logrotate -d prints what it would consider, but it is not proof that deleting or vacuuming logs is safe. Capture incident logs first.

  1. logrotate -d /etc/logrotate.conf
  2. journalctl --disk-usage

next steps

Related commands

Hosting Operations Can be slow

Find Logs Missing Logrotate Coverage

The biggest log risk is often the file no policy mentions.

find /var/log -type f -name '*.log' -printf '%p\n' | while read -r log; do grep -Rqs -- "$log" /etc/logrotate.conf /etc/logrotate.d || grep -Rqs -- "$(dirname "$log")/[*].log" /etc/logrotate.conf /etc/logrotate.d || printf '%s\n' "$log"; done
Hosting Operations Can be slow

Count Request IDs in Error Lines

Repeated request IDs can connect separate error lines to one failing path.

grep -Ei 'error|timeout|fatal|exception' /var/log/app/app.log | awk '{for (i=1;i<=NF;i++) if ($i ~ /^request_id=/) print $i}' | sort | uniq -c | sort -nr
Hosting Operations Read-only

Count App Errors by Minute

A minute-by-minute count shows whether an incident is a spike or a drip.

awk 'tolower($0) ~ /(error|fatal|timeout|exception)/ {minute=substr($1,1,16); count[minute]++} END {for (m in count) print count[m], m}' /var/log/app/app.log | sort -nr
Hosting Operations Can be slow

Scan Every CI Log for Error Lines

One grep pass can turn a log pile into a failure list.

grep -RInE 'error|failed|failure|exception|traceback' artifacts logs | head -50
Hosting Operations Can be slow

Review Log Files Before Cleanup

Before truncating logs, prove which log files are large and how old they are.

find /var/log -xdev -type f -printf '%10s %TY-%Tm-%Td %p\n' 2>/dev/null | sort -nr | head -50

next diagnostic step

Where to go from this command

Study mapping

Use this as independent command practice: read the notes, predict the output, then compare it with the example before using a real shell.

  • LPIC-1 style command-line practice
  • LFCS style performance-task practice
  • Linux+ style troubleshooting review

Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.