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

What is the command for " how many shell is running in your system or how many shell supported by your system " ?.

3 Answers  


What is shell and shell script?

0 Answers  


HOW TO CREATE 10 USERS IN UNIX(HP-UX) USING SHELL SHELL SCRIPT?

3 Answers   Patni,


write a shell program to check wheather a given string is pallindrome or not?

4 Answers  


How to enable the shell to know what program should be run to interpret the script?

3 Answers  






What does echo mean in scripting?

0 Answers  


What is the difference between running a script as ./scriptname.sh and sh scriptname.sh

1 Answers  


What is "test"? How it is used in shell scripting?

2 Answers  


What is bash coding?

0 Answers  


What is the significance of $#?

0 Answers  


What is the syntax of "grep" command?

4 Answers  


what is the difference between sh & bash shell?

1 Answers  


Categories