Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

logrotate

Direct answer

logrotate rotates, compresses and deletes old log files on a schedule (daily via a timer or cron), using /etc/logrotate.conf and per-application files in /etc/logrotate.d/.

When to use this

Use it when log files grow without limit, or rotated logs are missing or empty.

First 30 seconds

1. Rule exists: grep -r <file> /etc/logrotate.d.

2. Dry run: logrotate -d /etc/logrotate.d/<app>.

3. Ran recently? systemctl list-timers logrotate or cat /var/lib/logrotate/status.

4. Program still writes to the old file → missing postrotate reload.

5. Force once: logrotate -f /etc/logrotate.d/<app>.

Operational verification

schedule triggers → file matches a rule → renamed/compressed → program reopens its log → old files deleted

Evidence · next step

For Logging → logrotate, continue with the first unproven Topic check: Inspect the effective rule, include path and logrotate state for the target file. If that boundary is healthy, advance to the adjacent check: Run dry-run/verbose evaluation as evidence of eligibility, not proof of rotation. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.

Continue only after interpreting the current observation.
Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
linux
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformlinux
Scope / prerequisiteUse it when log files grow without limit, or rotated logs are missing or empty.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

5 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Operational evidence path Verify boundary

logrotate config/includes + state → eligibility trigger → rename/create or copytruncate → postrotate/service signal → writer file descriptor → compression/retention removal → fresh workload write → disk-space verification

Healthy evidence: the target rule becomes eligible as intended, generations are created/retained correctly, the writer transitions to the intended active inode, and a fresh event appears there without unexpected space leakage.

Step 2 Verification and output interpretation Verify boundary

Existing fast checks for this Topic. - Inspect the effective rule, include path and logrotate state for the target file.

  • Run dry-run/verbose evaluation as evidence of eligibility, not evidence of rotation.
  • After rotation, compare inode/file descriptors and verify writer reopen or documented copytruncate behavior.
  • Generate a fresh workload event and confirm it lands in the new active log; verify retention/compression afterward.

Verification chain. logrotate config/includes + state → eligibility trigger → rename/create or copytruncate → postrotate/service signal → writer file descriptor → compression/retention removal → fresh workload write → disk-space verification

Step 3 Commands Verify boundary
cat /etc/logrotate.d/nginx
logrotate -d /etc/logrotate.conf
logrotate -f /etc/logrotate.d/nginx
Step 4 Failure modes and next checks Narrow the fault

Suspicious evidence: dry-run is treated as execution evidence, postrotate failures are missed, copytruncate risks are ignored, or deleted-open files keep consuming space after apparent cleanup.

Step 5 Common mistakes Narrow the fault
  • Rotating without copytruncate or a reload, so apps keep writing to the old file.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points

After rotating, the program must reopen its log (postrotate reload, or copytruncate). Test with logrotate -d (dry run) and force with logrotate -f. Files not matching any rule are never rotated.

Key checks
  • logrotate -d <conf> — dry run
  • journalctl -b -p warning — warnings and errors since boot
  • journalctl -u <unit> -f — follow one unit's log
  • ls -lh /var/log — log files and sizes
  • logger -p user.info test — send a test message
ReferenceWhat it is1 section · depth on demand

Core model

Separate policy selection, rotation action, writer handoff and retention outcome. Check include order/state file, rotate trigger, naming/compression, create/copytruncate semantics and postrotate signaling; then show the writer has moved to the intended inode.

ReferenceImportant terms & boundaries5 sections · depth on demand

What this shows and what it does not

A successful logrotate invocation shows only the rotation actions it actually completed, but it does not show writer handoff, absence of race loss, reclaimed space or application health.

In depth

logrotate: rotating, compressing and expiring logs

logrotate keeps log files from growing forever. It renames them, compresses old ones and deletes the oldest. The logrotate(8) manual page documents the directives:

  • Frequency: daily, weekly, monthly, hourly, or size.
  • Retention: rotate N keeps N old copies.
  • Compression: compress, with delaycompress leaving the newest rotated file uncompressed.
  • Missing and empty logs: missingok and notifempty.
  • New files: create mode owner group creates the new log.
  • copytruncate: copies and truncates the original in place. The manual warns that some log data may be lost in the short gap.
  • Scripts: postrotate/endscript runs a command after rotation, and sharedscripts runs it once for all matched files.

The state is kept in /var/lib/logrotate.status. -d does a dry run, and -f forces rotation.

Telling the program about the new file

MethodWhen
postrotate with a reload or signalThe program can reopen its logs (nginx USR1, rsyslog HUP)
copytruncateThe program can't reopen files; accept a small risk of lost lines
The program rotates its own logsDon't use logrotate for those files
Logs go to the journaljournald handles size and age itself

A typical application configuration

host$ cat /etc/logrotate.d/report-api
/var/log/report-api/*.log {
    daily
    rotate 14
    compress
    delaycompress
    missingok
    notifempty
    create 0640 reportapi adm
    sharedscripts
    postrotate
        systemctl kill -s HUP report-api.service >/dev/null 2>&1 || true
    endscript
}
host$ sudo logrotate -d /etc/logrotate.d/report-api 2>&1 | tail -5
host$ sudo logrotate -f /etc/logrotate.d/report-api
host$ ls -l /var/log/report-api/
-rw-r----- 1 reportapi adm      0 Nov 28 14:20 api.log
-rw-r----- 1 reportapi adm 812331 Nov 28 14:20 api.log.1
-rw-r----- 1 reportapi adm  91210 Nov 27 00:00 api.log.2.gz
host$ grep report-api /var/lib/logrotate.status
host$ systemctl list-timers logrotate.timer

Why delaycompress

Right after rotation, the program may still write for a moment to the file it had open, which is now api.log.1. delaycompress waits until the next cycle before compressing it, so those last lines aren't cut off. On modern distributions, logrotate runs from a systemd timer (or cron daily), and a missed run is caught up later.

Documented example, not captured output.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

How it works at runtime

logrotate is part of Logging → logrotate. logrotate manages retention of file-based logs by selecting files on schedule/size, renaming or copying, compressing and removing generations, then optionally signaling/reopening the writer; rotation is complete only when the application continues writing to the intended new log without data loss.

Topic-specific state model. logrotate manages retention of file-based logs by selecting files on schedule/size, renaming or copying, compressing and removing generations, then optionally signaling/reopening the writer; rotation is complete only when the application continues writing to the intended new log without data loss.

Technical metadata. Host/distribution/systemd/rsyslog versions, boot ID, monotonic/realtime timestamp and timezone, NTP/clock state where relevant, producer binary/service/unit/PID/UID, logging transport/API, journal transport/facility/severity/priority, syslog source/destination/transport, file path/device/inode/ownership/permissions, journald storage/rate limits/retention, rsyslog input/ruleset/action/queue, logrotate rule/state/inode handoff, forwarding destination/receiver status, query filters, correlation ID/request ID and original workload result.

Interpretation rule. - logrotate dry-run output ≠ files were rotated.

  • Rotated file created ≠ application reopened the new active file.
  • copytruncate ≠ lossless handoff under concurrent writes.
  • Old generations removed ≠ current disk usage is reclaimed if deleted files remain open.

Quick reference

logrotate rotates, compresses and prunes log files, usually daily via a systemd timer or cron.

# /etc/logrotate.d/myapp
/var/log/myapp/*.log {
    daily
    rotate 14
    compress
    delaycompress
    missingok
    notifempty
    create 0640 myapp adm
    sharedscripts
    postrotate
        systemctl kill -s USR1 myapp.service >/dev/null 2>&1 || true
    endscript
}

logrotate -d /etc/logrotate.d/myapp       # dry run
logrotate -f /etc/logrotate.d/myapp       # force
cat /var/lib/logrotate/logrotate.status

The application must reopen its log file after rotation (signal or copytruncate, which can lose a few lines).

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Limits and how it fails

Primary failure point. A successful logrotate invocation shows only the rotation actions it actually completed, but it does not show writer handoff, absence of race loss, reclaimed space or application health.

ReferenceConfiguration & state1 section · depth on demand

Configuration, persistence and lifecycle

File logs may be created/rotated by logrotate, the application itself or a logging daemon. Rotation policy must match daemon reopen behavior.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doclinux current

Authoritative/upstream documentation reviewed for bounded claims in Logging → logrotate. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://systemd.io/ · confidence 94%
Technical changelog & impact

What changed and what may be affected

Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
logrotate linuxrotate logslog retentionpostrotate
Embedded reference data

Quick lookup tables

logrotate operational reference

Topic-specific lookup boundaries, proof limits and next-step Evidence for logrotate.

Lookup boundaryTopic-specific referenceOperational use
Scope / effective statelogrotate manages retention of file-based logs by selecting files on schedule/size, renaming or copying, compressing and removing generations, then optionally signaling/reopening the writer; rotation is complete only when the application continues writing to the intended new log without data loss.Establish exactly what this Topic owns before crossing into another subsystem.
Fast verificationPin host + boot ID + clock/timezone + event → identify producer/process → identify logging API/socket/file → verify collector receipt → inspect filtering/rate-limit → prove persistence/inode → verify rotation/retention → verify forwarding/remote receipt if required → query exact time/source → correlate with original workload.Use the shortest evidence path first; a fast check is a boundary test, not blanket proof.
Verification chainlogrotate config/includes + state → eligibility trigger → rename/create or copytruncate → postrotate/service signal → writer file descriptor → compression/retention removal → fresh workload write → disk-space verificationTrace requested/configured state through effective state to the observed workload result.
Failure boundaryA successful logrotate invocation proves only the rotation actions it actually completed; it does not prove writer handoff, absence of race loss, reclaimed space or application health.Stop broad troubleshooting at the first boundary that is not supported by evidence.
Positive evidenceCorrelated Linux logging evidence can establish this proof path: logrotate config/includes + state → eligibility trigger → rename/create or copytruncate → postrotate/service signal → writer file descriptor → compression/retention removal → fresh workload write → disk-space verificationUse this observation only for the specific claim it actually supports.
Evidence limitIt does not independently prove behavior outside the captured producer, collection, persistence, retention, forwarding, query or workload scope. A successful logrotate invocation proves only the rotation actions it actually completed; it does not prove writer handoff, absence of race loss, reclaimed space or application health.Do not promote a local success signal into end-to-end or adjacent-dependency proof.
Next troubleshooting checkContinue from the first unproven boundary: reproduce one exact event, align clock/boot/source identity, trace it through collection and storage, then verify retention/forwarding/query scope and independently repeat the original workload.Continue to the next unresolved boundary while preserving the original test condition.

logrotate · operational reference

Compact Linux state, persistence, verification and boundary reference for fast lookup.

Reference boundarylogrotate
Topic pathLogging → logrotate
Runtime statelogrotate manages retention of file-based logs by selecting files on schedule/size, renaming or copying, compressing and removing generations, then optionally signaling/reopening the writer; rotation is complete only when the application continues writing to the intended new log without data loss.
Fast checks- Inspect the effective rule, include path and logrotate state for the target file. - Run dry-run/verbose evaluation as evidence of eligibility, not proof of rotation. - After rotation, compare inode/file descriptors and verify writer reopen or documented copytruncate behavior. - Generate a fresh workload event and confirm it lands in the new active log; verify retention/compression afterward.
Verification chainlogrotate config/includes + state → eligibility trigger → rename/create or copytruncate → postrotate/service signal → writer file descriptor → compression/retention removal → fresh workload write → disk-space verification Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary.
Failure boundaryA successful logrotate invocation proves only the rotation actions it actually completed; it does not prove writer handoff, absence of race loss, reclaimed space or application health. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload.
Persistence ruleProve which configuration source owns the state, then prove that the running consumer loaded or generated the intended state.
Confirmation

Confirm action

Continue?