Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to find all directories that are directly inside the current directory and older than a specific age. The trick is, I only want to consider the age of the immediate descendants of the current directory, and not search through them recursively.

Usage example is for daily backups of files - a new directory is created every day, but the files placed inside that directory keep their timestamps and are often older. I want to be able to clean up old backups without deleting the old files in more recent snapshots.

It looks like find may not be able to do this, what unix tool (or a combination of them) do you recommend?

share|improve this question
add comment

3 Answers 3

up vote 16 down vote accepted

You can you -maxdepth and -mindepth with your modified/accessed/changed attribute search of choice, i.e.

find -maxdepth 1 -mtime 4

for 4 days.

Don't forget to exclude the . and .. results that find returns.

Useful link to many find examples.

share|improve this answer
    
Thanks. I tried that option (maxdepth) before, but used it incorrectly. Now this works! –  SaltyNuts May 19 '11 at 18:32
    
I think it would be -mtime +4 for older than 4 days rather than exactly 4 days. –  Duke Sep 17 '12 at 7:03
add comment

You're looking for the -maxdepth and -mindepth options.

share|improve this answer
add comment

find will work fine. Just add -maxdepth 1

share|improve this answer
add comment

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.