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

I am using this command to delete the files and folders older than 150 days

 find /media/Server/VPS/dailySQL/* -mtime +140 -exec rm -rf {} \;

The problem is that i get the error like below

find: `/media/May-08-Sat-2010': No such file or directory
find: `/media/May-11-Tue-2010': No such file or directory
find: `/media/May-12-Wed-2010': No such file or directory
find: `/media/May-13-Thu-2010': No such file or directory
find: `/media/May-14-Fri-2010': No such file or directory

why is that

share|improve this question

3 Answers 3

up vote 5 down vote accepted

Try this:

$ find /media/Server/VPS/dailySQL/ -mtime +140 | xargs rm -rf
share|improve this answer

Because you're removing the directories, and then trying to descend into them. Add -prune to the end.

share|improve this answer
    
This shall be the corret answer. –  jjmontes Mar 14 '13 at 2:40

Problem with a couple of the proposed suggestions is that if any of the files/directories have special characters, they will not be deleted. Doing an -exec in the submitters lins is really time consumming and better efficiency is done by piping the names to xargs and invoking the rm/rmdir in as few times as possible.

 touch /media/Server/VPS/dailySQL/.saver     
 find /media/Server/VPS/dailySQL -type f -mtime +140 -print0 | xargs -0 rm -f >/dev/null 2>&1
 find /media/Server/VPS/dailySQL -depth -type d -print0 | xargs -0 rmdir >/dev/null 2>&1

The second line deletes all the old files. I put a file in the top level directory to save it from destruction on the first line and finally you run through the directories depth-first and simply try to rmdir. If there is something still present, the rmdir will fail. Depth-first is necessary to remove empty sub-directories before a given directory is attempted to be removed.

Finally, notice -print0 and the -0 parameter on xargs. This allows you to process files that have spaces or other meta characters in them properly. This feature is available on most Linux systems I have been exposed to lately.

This is the type of scripting I used to remove /tmp and /var/tmp items.

Enjoy

share|improve this answer

Your Answer

 
discard

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