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
Which shell is the best?
What is the use of .sh file?
What is the best shell scripting language?
Print a given number, in reverse order using a shell script such that the input is provided using command line argument only.
Rewrite the command to print the sentence and convert the variable to plural: echo “i like $variable”.
What is difference between bash and shell?
I have to write Shells (Linux + Unix)for publishing packages and reports. Is it possible ? What are the differents executable programs ineed to call ?
What is a shell in operating system?
What is sudo command?
What is mac default shell?
What does $$ mean in shell script?
What can scripts do?
What does $@ mean bash?
Why should we use shell scripts?
Why are there shells on the beach?