I want to list the main folders in a directory that all their subfolders and files have a modified date older than a specific date. Any advice?

I've tried this: find . -type d -newermt '7/15/09' from this question but it returns subfolders and files. I want to return only the parent folder.

So for example if I'm in the correct directory and it has 100 main folders named folder1 ... folder100 then folder1 has subfolders 1..10 and 10 files and all of these subfolders and files hasn't been modified for 6 months then I want folder1 to be listed in the result not the subfolders and files.

  • Only one level deep or any file/subfolder? – nohillside Nov 5 '18 at 11:50
  • @nohillside I've updated the question, could you please check and advise? you can let me know if any more info needed. – Tak Nov 5 '18 at 11:56
  • A rather hacky way would be to run wc -l on the result ;-) – nohillside Nov 5 '18 at 12:00
  • @nohillside Thank you. Is it possible to provide an answer? :) as I also want to know how to set it to get main folders that non of its subfolders have been modified for 6 months and not with a specific date? – Tak Nov 5 '18 at 13:45
  • Ah, damn, misread your question and ignored the "all" part. Hmm. – nohillside Nov 5 '18 at 14:51
cd <to directory containting the main folders>
for d in */; do
    if [[ $(find "$d" -mtime -26w | fgrep -v .. | wc -l) -eq 0 ]]; then
        echo "$d"

should work, with the usual caveat about file/directory names containing newlines etc.

mtime compares the modification timestamp of the file with "now", -26w means "less than 26 weeks" (which is roughly 6 months).

| improve this answer | |
  • Thank you. I noticed something though, the modification date changes on macOS if I just opened the folder, which is not what I want, I want to know the ones who were not "modified" not just opened. Any advice? – Tak Nov 6 '18 at 7:55
  • @Tak I don‘t think there is a way to change if opening a folder in Finder changes the modification date – nohillside Nov 6 '18 at 11:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .