delete old logs

How To Delete File And Logs Older Than 30 Days In Linux

if you’re running out of space on your Linux machine and want to free up some space, so you need to delete the old logs or files which are not required anymore. let’s see, how to delete file.

I will show you many ways and commands to delete the files. you can also configure log server and move older logs to that server using logrotate command

Check Out : How To Install RabbitMQ Message Broker On Linux

if you want to delete 30 days old logs or files from the location, so run the below commands.

find /path/to/dir/ -mtime +30 -exec rm -rf {} \;

if you want to match files pattern and delete them.

find /path/to/dir/ -type f -mtime +days -name ’*.txt’ -execdir rm — ‘{}’ \;

Check Out :

you can also user -delete option to remove the files and this is the safest method.

find /path/to/dir/ -mdepth 1 -mtime +30 -delete

you can use -depth -print command instead of -delete to test this command.

You’re done

LEAVE A REPLY

Please enter your comment!
Please enter your name here

one × 2 =