LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to delete two days older files through script (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-delete-two-days-older-files-through-script-4175444590/)

azheruddin 01-07-2013 08:43 PM

How to delete two days older files through script
 
Hi,

want to delete files older than 2 days through script can i have a snippet of code..

Ztcoracat 01-07-2013 11:03 PM

Hi!

A good place to start would be to do some reading to be able to write your first script.
After you compose your script you could post it and other can give you insight/advice-

http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://linuxconfig.org/Bash_scripting_Tutorial
http://www.tldp.org/

This is a very good Bash Guide and was recommended by a Moderator; think you will find it helpful.
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html

http://tldp.org/LDP/abs/html/

You mentioned that you want to delete files that are more than 2 days old-
What type of files do you mean?

Some files are configured to run your OS and should not under any circumstances be deleted or removed.

kooru 01-08-2013 12:20 AM

Code:

find /path/for/your/files -mtime +2 -exec rm {} \;

jpollard 01-08-2013 09:04 AM

you forgot to quote the {} which happens to be a shell special character... (you did remember the ; though)

asimba 01-08-2013 12:18 PM

Quote:

Originally Posted by jpollard (Post 4865395)
you forgot to quote the {} which happens to be a shell special character... (you did remember the ; though)

his quote will work the way it is

find /path/ -mtime +num_days -exec rm {} \;


All times are GMT -5. The time now is 05:02 PM.