Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How to write an Auto scripting for deleting old files using
shell script and made a cron job to run on daily basis

Answer Posted / amit bondwal

#!/bin/bash
find /home/amitbondwal/ -type f -mtime +30 -exec rm -f {} \;
done
#change the directory path or name and number of days
#according to your requirement. This script will delete all
#the file older than 30 days in /home/amitbondwal directory

save the above script in a text file and run it by crontab

crontab -e

00 02 * * * /bin/sh /home/amitbondwal/scriptname.sh

This setting will run this script at 2 AM everyday.

Is This Answer Correct ?    12 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

In my bash shell I want my prompt to be of format '$"present working directory":"hostname"> and load a file containing a list of user-defined functions as soon as I log in, how will you automate this?

1155


What does the sh command do?

1086


how to print the 2-d, 3-d arrays in unix shell script programs please answer thi questio to my mail venusaikumar@gmail.com

2571


How to find all the files modified in less than 3 days and save the record in a text file?

1063


What are zombie processes?

1034


c program to display the information of given file similar to givan by the unix or linux command ls -l

2227


How to check if a directory exists?

1202


What are the disadvantages of shell scripting?

1205


‎What is a shell? · ‎Types of shell · ‎what is shell scripting?

985


What are the advantages of shell scripting?

1048


State the advantages of shell scripting?

1053


What is awk in shell script?

1235


Devise a script that takes file name as arguement(which must present in the current directory)and locates from your home directory tree all thpath names of its links.Then mail the list to self.

2222


How do I run a shell script on a mac?

1130


How do I run a shell script in powershell?

1138