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 -ctime catches permission changes that find -mtime misses

Find
~/tips/tip-find-ctime-permission-changes

find /etc /var/www -ctime -1 -ls

Finds files whose owner or permissions changed recently, even when their content did not.

A file’s modification time only changes when the content changes. A chmod or chown leaves it alone, so -mtime won’t show you who opened up a file last night.

That’s what the change time is for. ctime is updated when the content changes and also when the metadata changes: permissions, owner, the link count or a rename.

find /etc /var/www -ctime -1 -ls

This lists everything whose content or metadata changed in the last 24 hours. For minutes, use -cmin -30. Backdate a file by three days with touch and then run chmod 600 on it: -mtime -1 doesn’t find it, -ctime -1 does.

I like that it’s also harder to fake. touch can set the modification time to anything, but the change time is set by the kernel to the current time, and setting it again is exactly a change. That’s why ctime is the one to check when you wonder whether something was tampered with.

The downside is noise. Restoring a backup, running chown over a folder or even some package updates change the ctime of many files at once. And despite the name, ctime is not the creation time. A creation or birth time is something else, and many setups don’t let find see it at all.

Further reading: find(1) manual page, inode(7) 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