Remove old files from Dir 3days

Red hat Red hat linux 7.1
January 4, 2011 at 05:58:28
Specs: unix
please give me script for remove old files

See More: Remove old files from Dir 3days

Report •

#1
January 4, 2011 at 07:21:16
Use the find command. Check out this link:

http://www.computing.net/answers/un...


Report •

#2
January 4, 2011 at 13:37:28
find DIR -mtime +3 | xargs rm -rf DIR/*

Report •

#3
January 4, 2011 at 16:37:00
raghav2306:

Whatever you do, ignore dbstreams provided his post remains using this:

find DIR -mtime +3 | xargs rm -rf DIR/*

It is incorrect and dangerous! This comand at the end of the find command is incorrect:

r -rf DIR/*

Assuming that DIR is a directory, this comand deletes everything in the DIR directory.


dbstreams:

If you had bothered to read the link I posted, you would have seen that this exact question had been asked before and answered. A correct answer is:

cd <your directory>

find . -type f -mtime +3 -print|xargs rm -f

You don't need anything after xargs rm and you certainly don't need -r if just deleting files. That recursively deletes everything including directories.

You really need to be more careful or you'll cause somebody real damage.



Report •

Related Solutions

#4
January 10, 2011 at 13:50:03
I'd be inclined to listen to nails suggestions. I find his advice on scripts to be one of the best sources.

Why did it take me over a year to phone in a problem to ATT?


Report •

Ask Question