This time let's talk about how to delete files older than the n-th number of days using a simple script written in bash.
Create a file with the name "DelFileNDay.sh" using the utility "cat" for this.
cat > DelFileNDay.sh << EOF
#!/bin/bash
#Del file > 30 DAY DAY=30 DIR="/var/log/test/" find $DIR -type f -mtime +$DAY -exec rm -f {} \; EOF
Give the file maximum privileges with the help of the utility "chmod"
chmod 777 DelFileNDay.sh
Run bash-script
./DelFileNDay.sh
If you want the files to be deleted automatically, for example, once a day or a month, then put the script in the directory "/etc/cron.daily/" or "/etc/cron.monthly/"
That's all. Comment, subscribe. Bye everyone.
Comments powered by CComment