mrimin
mrimin

Reputation: 21

BASH find ctime not working as expected

I can't get "find" to locate old files. I am chaining my finds into one statement and all other segments are working fine. Here is a trimmed down version of what I have. It searches the directory tree of $path and creates separate temp files containing only new line characters for each item found: all files, files changed greater than 365 days ago, and all directories. The files and directories are working fine (as well as 6 other chained searches I didn't include here), but the ctime is returning 0 hits and I know there are matching files in the directory I am using.

find $path \
\( -type f -fprintf /tmp/files.txt "\n" \) , \
\( -type f -ctime +365 -fprintf /tmp/oldfiles.txt "\n" \) , \
\( -type d -fprintf /tmp/dirs.txt "\n" \)

This seems to be in line with the man page for find. It says that -ctime n finds files with a change time of n days. The + gives >n days, the - gives <n days, and no sign gives exactly n days. Despite the appearance that everything is in line, my temp file is still coming out with 0 lines. Any thoughts? Also of note, to conserve processing time I need to find these files while traversing the file system in one pass.

Upvotes: 2

Views: 3532

Answers (2)

Alex North-Keys
Alex North-Keys

Reputation: 4363

-ctime n File's status was last changed n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file status change times.

-mtime n File's data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification times.

Status = permissions, user, group, possibly ACLs, etc.

Content = your file data

If your files had their ownership changed 1.5 years ago and aren't showing up, that's a problem, but if it's the change in their content you're trying to detect, try -mtime.

Sidenote: -atime can be tricky to use in some systems, since it constitutes an access as well. Sidenote2: This is a find question, and isn't at all specific to bash.

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798686

"Change time" means "metadata change time", i.e. when the permissions or ownership has changed. Consider using mtime instead.

Upvotes: 5

Related Questions