How to write an Auto scripting for deleting old files using
shell script and made a cron job to run on daily basis
Answer Posted / 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 View All Answers
How will you print the login names of all users on a system?
State the advantages of shell scripting?
Give some situations where typing error can destroy a program?
How do we create command aliases in a shell?
Differentiate between ‘ and ” quotes.
What is the command to find out users on the system?
What is the first line in every perl script called?
What is shift command in shell script?
Which scripting language is best for automation?
How does shell scripting work?
Explain about return code?
What's the difference between scripting and coding?
Write a script to print the first 10 elements of fibonacci series.
What is @echo off?
What does it mean by #!/Bin/sh or #!/Bin/bash at the beginning of every script?