Showing results for 
Search instead for 
Do you mean 

Deletion of files

Go to Solution
Frequent Advisor

Deletion of files

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.
Esteemed Contributor [Founder]

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

Acclaimed Contributor [Founder]

Re: Deletion of files


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 :-)


Esteemed Contributor [Founder]

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.