Showing results for 
Search instead for 
Do you mean 

Deletion of files

SOLVED
Go to Solution
Frequent Advisor

Deletion of files

Hello,
The task is to delete any files under directory /home/hansen/download which are older than 210 days.

Can someone help me with a script for automating this?

Thanks in advance.
4 REPLIES
Esteemed Contributor

Re: Deletion of files

Hello hansen.
Test the following command out in some unimportant folder first.

Hope it helps.

find /home/hansen/download/* -mtime +210 -exec rm {} \;
Knowledge is power.
Frequent Advisor

Re: Deletion of files

Thanks.
Acclaimed Contributor

Re: Deletion of files

Hi:

You can improve the performance of your removal by using this syntax:

# find /home/hansen/download -type f -mtime +210 -exec rm {} +

...instead of:

# find /home/hansen/download/* -mtime +210 -exec rm {} \;

Notice that the path to find() does not include the wildcard. You don't need the shell expanding this list. Next, files are specifically selected with '-type f'. Lastly, the terminator to '-exec' is a "+" character. This causes multiple arguments to be assembled for each 'rm' command spawned. Your processor and will love you :-)

Regards!

...JRF...
Highlighted
Esteemed Contributor

Re: Deletion of files

Thanks for improving/refining my script
Mr. Ferguson.

I had no idea I was putting extra unneeded work on my processor.

Live and learn.
Knowledge is power.