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 have a list of +30.000 directory and I have to delete all the directories and their content from 2005 to 2006, via terminal. Thanks for help

share|improve this question

2 Answers 2

up vote 2 down vote accepted

If I understood you correctly, you can use the following command:

$ find /path/to/dir -mtime +10 -exec /bin/rm -rf {} \;

This will remove all files/folders that are older than 10 days. There are other options like -atime. You can see man find for more info.

share|improve this answer
    
yes thanks but I don't want to delete folders older than 10 days, only from 01-01-2005 to 31-12-2006 –  Kreker Feb 8 '11 at 11:04
    
So, you can find how many days your files are old and execute similar command. Do you have files older than 01-01-2005? If so, you can copy them to another directory. –  Khaled Feb 8 '11 at 11:28

If you have GNU find, you can do this:

find /start/path -newermt 2004-12-31 ! -newermt 2006-12-31 -delete

Use -ls instead of -delete to test.

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.