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.

Watch this command run

Command transcript

This sanitized transcript shows the commands and output shape without exposing host details.

demo@lab:~$

$ logrotate -d /etc/logrotate.conf

reading config file /etc/logrotate.conf
including /etc/logrotate.d
reading config file nginx
reading config file app
rotating pattern: /var/log/nginx/*.log  after 1 days (14 rotations)
considering log /var/log/nginx/access.log
  log does not need rotating
considering log /var/log/nginx/error.log
  log does not need rotating
rotating pattern: /var/log/app/app.log  52428800 bytes (7 rotations)
considering log /var/log/app/app.log
  log does not need rotating

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

rotating pattern: /var/log/nginx/*.log  after 1 days (14 rotations)
considering log /var/log/nginx/access.log
considering log /var/log/nginx/error.log
rotating pattern: /var/log/app/app.log  52428800 bytes (7 rotations)
considering log /var/log/app/app.log
View commands shown

These are the commands shown in the sanitized transcript.

Commands shown

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

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

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 /lab/disk-inode-cleanup/var/log -xdev -type f -printf '%10s %TY-%Tm-%Td %p\n' | sort -nr
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' fixtures/incidents/app.log | awk '{for (i=1;i<=NF;i++) if ($i ~ /^request_id=/) print $i}' | sort | uniq -c | sort -nr
Hosting Operations Can be slow

Tail the Failing CI Lines

Skip the full CI log and jump straight to lines that usually explain the failure.

grep -RInE 'error|failed|exception|traceback|fatal' logs/ | tail -50
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.

  • lpic1:103-gnu-unix-commands
  • lfcs:essential-commands
  • lfcs:operations-deployment
  • lfcs:services-logs
  • linuxplus:automation-scripting
  • linuxplus:provisional
  • risk:read-only

Useful for

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

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