Deleting files older than 30 days automatically

1. create the script to find files older than 30 days and delete the files, suppose the script file name is deletefile

can use this

find  /home/mujoko/archive/  -mtime +30    -exec rm {} \;  // find files the older than 30 days in /home/mujoko/archive/  folder, make sure there is space after rm and before {}


find  /home/mujoko/archive/ -mtime +30 |xarsg rm // using this script its possible we face error too many parameters if the files is to many to delete

2. Login as root

3. Configure crontab by execute

crontab -e mujoko  //replace mujoko by your own username

4. Edit crontab by adding

30 1 * * * /home/mujoko/deletefile    //deletefile is the file you create at step 1

5. Save your crontab.

Walaaaa, your file within /home/mujoko/archive will be deleted when the files is older than 30 days.







Tagged: , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: