Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need to delete folderx which are not accessed for seven days, easily I can do it with next:

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

The probelm is when I have subfolder marked for deletion and parent folder is not, I can do it with with adding maxdepth 1, but actually it is not solution from top to bottom, I need solution to define from bottom to top where I have

folder 1 (accesed 8 days ago)
-> folder 2 (accessed 8 days ago)
-> folder 3 (accessed 4 days ago),

With maxdepth 1 it will delete first two and also folder 3 which I don't want do do it.

So actually I need some solution from bottom to top for this. If subfolder is marked for deletion and parent is not etc.

share|improve this question
    
Are you looking for tmpreaper/tmpwatch? –  derobert Mar 24 at 22:22
    
use recursion instead of find –  RSFalcon7 Mar 24 at 22:23
    
i can not use tmpreaper and tmpwatch, @RSFalcon7 what actually you meant when you sad recursion insted of find ? –  klerk Mar 24 at 22:28
1  
create a function e.g. that deletes the current dir only if for all subdirs were not accessed within 7 days or it is empty, the return value is a key here, since you pass info using bottom-up approach –  RSFalcon7 Mar 24 at 22:34
    
i tried but without success can you help me pls @RSFalcon7 –  klerk Mar 25 at 8:53

1 Answer 1

find /path/folder -type d -ctime +7 | xargs rm -rf

ctime +7 only consider the ones with modification time older than 7 days

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.