atime vs mtime vs ctime in Linux: How find, rsync, and ClamAV Use File Timestamps

Last Verified On: Kernel 6.8 / 6.12 LTS / Ubuntu 24.04 LTS & Debian 12/13 Moderate (Service Restart)

Direct Answer / TL;DR

atime logs reads, mtime logs data writes, ctime logs inode/metadata changes and is kernel-managed. find's -atime/-mtime/-ctime round to 24-hour periods (use -amin/-mmin/-cmin for minutes); rsync mirrors on mtime via -t/--size-only/-c and cannot preserve ctime. Diagnose with stat -c '%x %y %z' on Ubuntu 24.04, Debian 12, and RHEL 9.

stat -c '%n | a=%x | m=%y | c=%z | b=%w'

Command / Parameter Syntax Breakdown

The VFS keeps three POSIX clocks in struct inode: i_atime (raised by read(2) and mmap page faults), i_mtime (raised only by data writes and truncation), and i_ctime (raised by every inode mutation — chmod, chown, link/rename, size change, and every mtime update itself; pure atime updates never raise ctime on Linux). The folklore ‘ctime = creation time’ is wrong: birth time is a fourth, non-POSIX field, stx_btime from statx(2) (kernel 4.11+), printed by stat -c %w. Two kernel facts drive everything below: ctime can never be backdated by userspace, and reads bump atime but never mtime or ctime. Read cost is governed by mount policy: relatime (kernel default since 2.6.30) re-arms atime only when atime < mtime, atime < ctime, or the previous atime is older than 24 h; strictatime updates on every read; noatime never updates; lazytime keeps time changes dirty in RAM until an unrelated writeback, sync, memory pressure, or its 24 h timer.

# All four linux timestamps in one line (GNU coreutils stat)
stat --printf='%n  a=%x  m=%y  c=%z  b=%wn' /var/lib/clamav/daily.cvd

# Effective atime policy of the mount backing a path
findmnt -T /var/lib/clamav -no TARGET,FSTYPE,OPTIONS

# Epoch-sorted mtime report, no fork/exec cost (GNU find -printf)
find /var/lib/clamav -type f -printf '%T@ %T+ %pn' | sort -nr

Granularity matters when programs compare timestamps: ext4, XFS and btrfs keep nanoseconds; vfat has 2 s resolution for mtime and 10 ms for atime/ctime, and on FAT the exposed ‘ctime’ is synthesized from a different DOS field. Never demand sub-second timestamp equality across filesystems — rsync compensates with --modify-window=1 on FAT/SMB targets.

Flag-by-Flag Behavior & Edge Cases

  • stat — %x/%X atime, %y/%Y mtime, %z/%Z ctime, %w/%W birth time; lower-case directives are human-readable, upper-case are epoch seconds. %w prints - (and %W prints 0) where kernel or filesystem lacks birth time, e.g. tmpfs or old NFS exports. ctime (%z) is the ‘who touched this inode’ alarm: it moves on chmod, chown, hardlink/rename, truncating writes and every touch.
  • touch — -a sets atime only, -m mtime only, -h/--no-dereference targets the symlink itself, -d '@1700000000' takes an epoch (GNU coreutils). Every invocation also stamps ctime to now; there is no userspace bypass.
  • find -atime/-mtime/-ctime n — 24 h bucket semantics with floor rounding: a file modified 36 h ago matches -mtime 1 and -mtime +0, but NOT -mtime +1. +n means ‘older than n full buckets’, -n ‘younger’, bare n the exact bucket. Minute precision: -amin/-mmin/-cmin. -daystart -mtime 0 means ‘since 00:00 today’. -newer REF / -newerXY (X,Y in a m c B, Y=t for an explicit timestamp, e.g. -newermt '2025-01-01'; -newerBt for birth time) compare across clocks. find only lstat(2)s candidates, so scanning never perturbs atime; -exec cat {} + would.
  • rsync -t (part of -a) — activates the size+mtime quick check. Without -t the quick check degrades to size-only, so equal-size files with wrong mtime are silently skipped. -c replaces it with whole-file checksums (reads both trees); --size-only drops mtime from the comparison. rsync 3.2.0+ adds -U/--atimes (Ubuntu 24.04/Debian 12 ship 3.2.7, RHEL 9 3.2.3); combine as -aUO so -O/--open-noatime stops the source read from clobbering atime (O_NOATIME needs ownership or CAP_FOWNER — run as root). ctime is never transported: the destination kernel stamps it on every write.
  • relatime / strictatime / nodiratime / noatime / lazytime — the read-side mount policies. noatime implies nodiratime and is the standard choice for read-heavy services (mail spools, database files, scan targets).
  • ClamAV (clamscan/clamd) is a pure read workload — one scan read()s every file, so its I/O profile is dictated by the atime policy of the scan root: strictatime costs one metadata writeback per file, noatime nearly nothing (why mail-server guides pin maildirs on noatime). freshclam databases in /var/lib/clamav/ carry release mtimes, so timestamp-faithful rsync mirrors stay idempotent, and ‘scan only recent activity’ patterns anchor on find -mmin.

Safe Dry-Run & Verification Workflow

  1. Baseline the four clocks and the effective policy; b=%w returns - on filesystems without birth time.
    $ stat --printf='%n  a=%x  m=%y  c=%z  b=%wn' /var/lib/clamav/daily.cvd
    /var/lib/clamav/daily.cvd  a=2025-11-29 22:01:44.912 +0100  m=2025-11-26 04:12:31.000 +0100  c=2025-11-26 04:12:31.001 +0100  b=2025-11-26 04:12:30.997 +0100
    $ findmnt -T /var/lib/clamav -no OPTIONS
    rw,relatime,errors=remount-ro
  2. find is a dry-run whenever no action flag (-delete, -exec) is present. Predict by bucket first:
    $ find /var/lib/clamav -type f -mtime +30 -printf '%T+ %pn' | sort
    2024-10-02 04:12:31.000000000 +0200 /var/lib/clamav/main.cld
    $ find /var/spool -type f -mmin -60 -printf '%T@ %pn' | sort -nr | head
    1732974222.4140000000 /var/spool/mail/alice
  3. rsync: dry-run twice and diff the itemized output. Extra lines under -ainc are same-size, same-mtime files whose bytes differ — a mtime blind spot from clock skew, backdating or FAT 2 s granularity. The arrow shows push vs pull direction; attribute letters are lower-case in -n dry-runs and upper-case in real runs.
    $ rsync -ain /var/lib/clamav/ /backup/clamav/
    >f+++++++++ daily.cvd
    $ rsync -ainc /var/lib/clamav/ /backup/clamav/
    >f+++++++++ daily.cvd
    >fc........ main.cld
  4. Execution plus re-verification: destination mtime must equal the source within filesystem granularity; a different ctime/btime on the copy is correct kernel behavior.
    rsync -aUO /var/lib/clamav/ /backup/clamav/
    find /var/spool -type f -mmin -60 -print0 | xargs -0 clamscan --infected --no-summary
    stat -c '%n m=%y b=%w' /var/lib/clamav/daily.cvd /backup/clamav/daily.cvd

Multi-Distro Differences

Kernel semantics are identical everywhere; packaging and toolchain versions move: the ClamAV repository (EPEL on the RHEL family), the rsync version floor for --atimes (3.2.0), and busybox’s reduced stat/find on Alpine.

Ubuntu / Debian

# coreutils 9.x (%w ok), rsync 3.2.7 (-U/-O ok)
apt-get install -y rsync clamav clamav-daemon clamav-freshclam
stat -c '%n btime=%w' /etc/hostname
findmnt -T / -no OPTIONS | tr ',' 'n' | grep -E 'atime|lazy'
# ext4 offline ctime/btime check: read-only query, root + real block device
debugfs -R 'stat /etc/hostname' /dev/mapper/vg-root 2>/dev/null | grep -E 'ctime|crtime'

RHEL / AlmaLinux / Rocky

# ClamAV from EPEL; rsync 3.2.3 still supports -U/-O
dnf install -y epel-release && dnf install -y clamav clamav-update clamd rsync
stat -c '%n btime=%w' /var/log/messages
xfs_io -c 'statx' /var/log/messages | grep -E 'ctime|btime'
findmnt -T / -no FSTYPE,OPTIONS

Arch Linux

# Newest coreutils and rsync 3.3+: full timestamp feature set
pacman -S --needed rsync clamav
stat -c '%x | %y | %z | %w' /etc/hostname
findmnt -T / -no OPTIONS | tr ',' 'n' | grep -E 'atime|lazy'

Alpine / Containers

# busybox stat lacks %w; busybox find lacks -newermt/-newerXY
apk add coreutils findutils rsync clamav clamav-freshclam
stat -c '%n btime=%w' /etc/os-release
find /var/lib/clamav -type f -mmin -60 -print

Destructive Traps & Rollback Procedure

Safety Check: timestamp filters look innocent, but timestamp-driven find (-delete, -exec rm), backdating via touch -d, and mount -o remount all carry operational blast radius. Always write a baseline file (epoch + path) under /var/tmp/*.before first — it is the only userspace rollback for atime/mtime. ctime and btime are kernel-managed and are not userspace-restorable.

Canonical retention cleanup — baseline, dry-run, execute:

# 0) baseline capture (rollback file): mtime epoch + path
find /srv/web -type f -printf '%T@ %pn' > /var/tmp/mtimes.before
# 1) dry-run: read-only candidate list; audit every line
find /srv/web -type f -mtime +30 -printf '%T+ %pn' | sort
# 2) execute only when the list above matches expectations
find /srv/web -type f -mtime +30 -delete

Rollback of a botched touch sweep restores mtime to whole seconds (add an %A@ baseline for atime; ctime/btime are gone for good):

while read -r T p; do
  touch -m -d "@${T%.*}" -- "$p"
done < /var/tmp/mtimes.before

ctime/btime surgery is offline, ext-family-only, forensic-grade work — unmount the filesystem first and verify immediately with debugfs stat:

debugfs -w -R 'set_inode_field img.jpg ctime 20240101090000' /dev/mapper/vg-root
debugfs -R 'stat img.jpg' /dev/mapper/vg-root | head

Mount-policy changes are reversible: snapshot live options and re-apply them on rollback.

findmnt -T /srv -no OPTIONS > /var/tmp/mountopts.before
mount -o remount,noatime /srv
# rollback: re-apply the exact option set from /var/tmp/mountopts.before
mount -o remount,relatime /srv

Rule of thumb: find filters on linux timestamps, rsync replicates mtime and cannot set ctime, ClamAV pays the atime bill — read with stat, predict with dry-runs, and let the mount policy decide what reads cost.

Frequently Asked Edge Cases

Does running find -mtime or -atime alter the timestamps it reads?

No. find resolves each candidate with lstat(2), a metadata-only syscall that never raises atime; only read(2)/mmap access does. Pipes like `find ... -exec cat {} +` do bump atime on every listed file.

Why does rsync re-transfer files whose mtime looks identical on both sides?

The transfer ran without -t, so the quick check fell back to size-only while the receiver stamped fresh mtimes; restore with rsync -a (includes -t), add --modify-window=1 for FAT/SMB clock skew, and use -c when mtime is untrustworthy.

Can root set ctime back in time to hide edits?

No userspace call, including touch and chmod, can set ctime — the kernel stamps it on every inode mutation, so any attempt updates it to now; only offline `debugfs set_inode_field` on an unmounted ext-family filesystem can write ctime/crtime.

References & Upstream Docs

  1. Linux man-pages: man 7 inode, man 2 statx
  2. GNU coreutils: man 1 stat · GNU findutils: man 1 find (TIME FORMATS section)
  3. rsync manual: man 1 rsync — --atimes/--open-noatime added in 3.2.0
  4. e2fsprogs: man 8 debugfs (set_inode_field, offline timestamp surgery)

Related Concepts