Hello!

How to find the directory that was changed 7 days ago and delete it completely?

I use the command:

find /folder/folder1/* -mtime +7 -delete 

But only the contents of directories from folder1 are deleted.

    2 answers 2

    This is the deletion of a directory that changed 7 or more days ago:

      find /folder/folder1 -type d -mtime +7 | xargs rm -rf 

    If you need exactly 7, then +7 should be replaced by 7 .

       rm -rf $(find /folder/folder1 -mtime 7) 
      • @De_frag has the correct version - I forgot about the file type :) - isnullxbh
      • Well, this option is also working. The only thing I do not know what is the limit on the length of the $(find /folder/folder1 -mtime 7) structure $(find /folder/folder1 -mtime 7) . If there will be a million search results, will bash ... choke ... - de_frag
      • @de_frag, yes, choking) Does xargs work fine with a large number of input arguments? - isnullxbh
      • xargs chokes too, but it has the magic option -I{} . If you do this: find /folder/folder1 -type d -mtime +7 | xargs -I{} rm -rf {} find /folder/folder1 -type d -mtime +7 | xargs -I{} rm -rf {} , then rm will be run separately for each search result, not for the entire line. Frankly, I did not test it on large quantities. Therefore, I can not vouch for the answer. - de_frag
      • @de_frag, understood, thanks for the explanation! - isnullxbh