0

Looking to delete the folder - IF all files inside that folder are over a year old.
If even 1 file isn't, I need to leave the ENTIRE folder untouched. Very specific, I know.

I should add I have a good amount of folders to complete this on.

  • [BashFAQ #3](https://mywiki.wooledge.org/BashFAQ/003) will let you find the date of the newest file. – Charles Duffy Apr 14 '18 at 01:31
  • Alternately, you could check whether the output from the command given in https://stackoverflow.com/questions/34021732/list-all-files-older-than-x-days-only-in-current-directory is empty. – Charles Duffy Apr 14 '18 at 01:32
  • 1
    @l0b0, I don't believe the proposed duplicate is a match -- they want to preserve *all* files if *any* are newer. (At the same time, I don't think it's a good question as-asked -- I provided the links above to give the OP everything they need to answer it themselves; if they edited the question to show where they got stuck when making such an attempt, vs just being a please-write-my-code-for-me request as it is now, *then* it would be a good question). – Charles Duffy Apr 14 '18 at 02:02
  • Charles- great help and I thank you. I am not asking for anyone to write my code I can assure you. I am very new. – Pete White Apr 14 '18 at 02:06
  • @CharlesDuffy You're right. There's no code in the question though, so it's likely to be closed as off topic for asking for an existing tool. What have you tried so far? – l0b0 Apr 14 '18 at 02:11
  • I haven't, because I can't find the logic to make this work. The only thing I have is Charles answer of BashFAQ #3 to at least get my list. – Pete White Apr 14 '18 at 02:20
  • @PeteWhite, ...so, once you've found the newest file in a directory, the next goal is to determine whether it's more than a year old. [How to get time since file was last modified in seconds in bash](https://stackoverflow.com/questions/19463334/how-to-get-time-since-file-was-last-modified-in-seconds-with-bash) isn't a bad place to start -- you can then compare that to (60*60*24*365), if generalizing to 365-day years is good enough. – Charles Duffy Apr 14 '18 at 18:15

0 Answers0