Force or dry-run log rotation with logrotate

Preview what logrotate will do, or rotate logs immediately after big config changes.

LinuxlogsrotatecleanupMedium risk
Rehearse with sudo logrotate -d /etc/logrotate.conf, then apply for real with sudo logrotate -f /etc/logrotate.conf.

01Command

Command
$ sudo logrotate -f /etc/logrotate.conf

02What it does

logrotate normally runs from a daily systemd timer or cron job, rotating and compressing logs that exceed their size or age rules. The -d flag does everything except actually touching files, printing which logs would rotate and why — ideal for testing a new /etc/logrotate.d/ rule. -f forces rotation on every log, regardless of schedule.

03Risk

RiskMedium risk
Requirementslogrotate package (preinstalled on virtually every distro); root access for system log paths.
!Warning: -f rotates all logs including tiny ones, which restarts many services' log files at once — expect a burst of new empty logs. Always dry-run (-d) first: a wrong glob in a custom rule can silently skip logs or rotate files other daemons still hold open.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • logrotate(8) - Linux manual page
    man7.org · community · 2026-09-17
    Evidence: SYNOPSIS logrotate [--force] [--debug] [--state file] configfile ... with --force forcing rotation even when not due.
  • logrotate(8) — Debian bookworm
    Debian Manpages · community · 2026-09-17
    Evidence: Documents -f, --force, -d, --debug (dry run) and -v, --verbose for the log rotation tool.

Last verified: 2026-09-19 · Category: Files & Folders

06Related solutions