Find directories with all files inside older than X?
It's probably possible to do this without creating files using process substitution or something, but here's a quick-and-dirty solution:
find . -type f -mtime +30 -printf '%h\n' | sort | uniq > old.txt
find . -type f -mtime -30 -printf '%h\n' | sort | uniq > new.txt
grep -vf new.txt old.txt
The first command outputs the path of every file modified more than 30 days ago (in find's -printf
-- at least with the GNU find on my system -- %h
prints the whole path except for the actual filename), then sorts those and gets rid of any duplicates, and puts the whole thing into a file called old.txt
.
The second command does the same but with every file modified less than 30 days ago, and puts them into another file, new.txt
.
The grep line prints every line from old.txt that doesn't appear in new.txt -- so it will give you a list of directories that contain only files that were last modified more than 30 days ago.
This is all using the GNU versions of the utilities. I don't know if the syntax matches up on the BSD versions, etc.
Finally figured out the magic one-liner:
for dir in `find . -type d -mtime +30`; do test `find $dir -type f -mtime -30 -print -quit` || echo $dir; done
This prints any directories that have a modification time greater than 30 days and no files modified within the last 30 days.