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
Why should we use shell scripts?
Write a shell script that adds two numbers if provided as the command line argument and if the two numbers are not entered throws an error message.
determine the output of the following command: echo ${new:-variable}
write a shell script to generate a alert ? like when ur birthday came then generate a alert ur birthday is today like that ?
Determine the output of the following command: name=shubham && echo ‘my name is $name’.
How to get the last line from a file using just the terminal?
How do I start a shell script?
What is the use of echo in shell script?
What is shell variable?
Is shell script a programming language?
Suppose you execute a command using exec, what will be the status of your current process in the shell?
What are the 3 standard streams in linux?
What are the disadvantages of shell scripting?
What is awk in shell scripting?
How do I run a script on mac?