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 |
Is scripting and coding the same thing?
What are the different kinds of loops available in shell script?
What are the different variables present in linux shell?
Is it possible to substitute "ls" command in the place of "echo" command?
How will I insert a line "abcdef" at every 100th line of a file?
What will happen to my current process when I execute a command using exec?
How do you rename the files(*.sh) with file names containing space in it?for example "interview question.sh" needs to rename to "interview-question.sh". Appreciate your inputs.Thanks.
How can I Debug a shell scripts and Perl scripting?? or How do you debug a shell scripting and perl scripting ( at the compile time error or run time error) in Unix environment ?
What is scripting autism?
How to get script name inside a script?
What are the disadvantages of shell scripting?
What is a shell made of?