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

Why should we use shell scripts?

989


Write a shell script that adds two numbers if provided as the command line argument and if the two numbers are not entered throws an error message.

1229


determine the output of the following command: echo ${new:-variable}

913


write a shell script to generate a alert ? like when ur birthday came then generate a alert ur birthday is today like that ?

4046


Determine the output of the following command: name=shubham && echo ‘my name is $name’.

929


How to get the last line from a file using just the terminal?

1147


How do I start a shell script?

1121


What is the use of echo in shell script?

948


What is shell variable?

861


Is shell script a programming language?

975


Suppose you execute a command using exec, what will be the status of your current process in the shell?

1020


What are the 3 standard streams in linux?

1047


What are the disadvantages of shell scripting?

1119


What is awk in shell scripting?

978


How do I run a script on mac?

1025