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
In my bash shell I want my prompt to be of format '$"present working directory":"hostname"> and load a file containing a list of user-defined functions as soon as I log in, how will you automate this?
What does the sh command do?
how to print the 2-d, 3-d arrays in unix shell script programs please answer thi questio to my mail venusaikumar@gmail.com
How to find all the files modified in less than 3 days and save the record in a text file?
What are zombie processes?
c program to display the information of given file similar to givan by the unix or linux command ls -l
How to check if a directory exists?
What are the disadvantages of shell scripting?
What is a shell? · Types of shell · what is shell scripting?
What are the advantages of shell scripting?
State the advantages of shell scripting?
What is awk in shell script?
Devise a script that takes file name as arguement(which must present in the current directory)and locates from your home directory tree all thpath names of its links.Then mail the list to self.
How do I run a shell script on a mac?
How do I run a shell script in powershell?