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



How to write an Auto scripting for deleting old files using shell script and made a cron job to ru..

Answer / 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

More Shell Script Interview Questions

In a file , how to retrieve the lines which are the multiples of 50 ? like 50,100,150th lines etc.

9 Answers   Amazon,


What is the difference between a shell variable that is exported and the one that is not exported?

6 Answers  


Write a shell script to looking at the log file to see if the test has passed or not

2 Answers   TCS,


What is Linux language details

0 Answers   Quick Heal,


What command needs to be used to take the backup?

1 Answers  


what are special characters and explain how does text varies by the usage of single quotes,double quotes and back quotes?

1 Answers  


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

1 Answers  


Explain about "s" permission bit in a file?

1 Answers  


Why we are writting shell scripts? Plz if possible explain it briefly.

6 Answers   ITC Infotech,


I want to upload a file to remote server through ftp daily.Can anyone suggest how to make a shell script for that.I hv credentials for that ftp

1 Answers  


What is the difference between scripting and coding?

1 Answers  


What is in a script?

1 Answers  


Categories