brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: find -atime is often wrong, because Linux barely updates access times

Find
~/tips/tip-find-atime-relatime

find /srv/share -type f -atime +365

Shows why searching for files nobody read lately with find gives misleading results.

It sounds like the perfect cleanup: list files that nobody has opened for a year with find -atime +365. On most Linux systems the answer is less reliable than it looks.

find /srv/share -type f -atime +365

-atime tests the access time, the moment a file was last read. Writing it on every read costs a disk write per read, so modern systems mount with relatime by default. With relatime the access time is only updated if it was older than the last change, or more than a day old. Some systems use noatime, where it is never updated at all.

Check which one you have before you trust the result:

findmnt -no OPTIONS -T /srv/share

With relatime, -atime +365 still works reasonably: a file that was read at some point this year has a recent access time. With noatime it means nothing, and the list is the same as files that weren’t changed for a year. Backup and indexing tools can also read every file and reset the access time for everything.

So I’d treat the list as a suggestion and never pipe it into a delete. For an actual cleanup, the modification time with -mtime is the more honest test.

Further reading: find(1) manual page, mount(8) manual page

More Find tips find / -maxdepth 1 -fstype proc find /backup -name '*.gz' ! -exec gzip -t {} \; -print 2>/dev/null find /srv/downloads -type f -size +100M -size -1G -exec ls -lh {} + find /srv/data -depth -print find /srv -xdev -samefile /srv/downloads/movie.mkv All Find tips (46) All topics

Link