How to write an Auto scripting for deleting old files using
shell script and made a cron job to run on daily basis
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 |
What is the command for " how many shell is running in your system or how many shell supported by your system " ?.
What is shell and shell script?
HOW TO CREATE 10 USERS IN UNIX(HP-UX) USING SHELL SHELL SCRIPT?
write a shell program to check wheather a given string is pallindrome or not?
How to enable the shell to know what program should be run to interpret the script?
What does echo mean in scripting?
What is the difference between running a script as ./scriptname.sh and sh scriptname.sh
What is "test"? How it is used in shell scripting?
What is bash coding?
What is the significance of $#?
What is the syntax of "grep" command?
what is the difference between sh & bash shell?