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 to find out users on the system?
write a non recursive shell script that accepts any number of arguments and prints them in the reverse order
What is the difference between a variable and value?
How can you get the value of pi till a 100 decimal places?
whta is the use of "exec" command?
How do I run a .sh file?
What is the use of script interpreter in shell scripting?
How do I open the shell prompt?
Can you write a script to portray how set –x works?
What are the default permissions of a file when it is created?
What is $1 in shell scripting?
one folder contains lot of students name but I want to fetch hello with every student name individually using shell script