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

Is scripting and coding the same thing?

0 Answers  


What are the different kinds of loops available in shell script?

3 Answers  


What are the different variables present in linux shell?

0 Answers  


Is it possible to substitute "ls" command in the place of "echo" command?

0 Answers  


How will I insert a line "abcdef" at every 100th line of a file?

2 Answers  


What will happen to my current process when I execute a command using exec?

0 Answers  


How do you rename the files(*.sh) with file names containing space in it?for example "interview question.sh" needs to rename to "interview-question.sh". Appreciate your inputs.Thanks.

5 Answers   Wells Fargo,


How can I Debug a shell scripts and Perl scripting?? or How do you debug a shell scripting and perl scripting ( at the compile time error or run time error) in Unix environment ?

4 Answers  


What is scripting autism?

0 Answers  


How to get script name inside a script?

0 Answers  


What are the disadvantages of shell scripting?

0 Answers  


What is a shell made of?

0 Answers  


Categories