How to Delete old Files in Linux


This is the best practice to eliminate old unused records from your server. For instance, in case we are running day by day/hourly reinforcement of documents or information base on the server then there will be a lot of garbage made on the server. So spotless it routinely. To do it you can discover more seasoned records from the reinforcement registry and clean them. 

This article portray you to how to discover and erase documents more seasoned than 30 days. Here 30 days more seasoned means the last alteration date is before 30 days.


1. Delete Files more than 30 Days olds

You can use the find command to search all files modified older than X days. And also delete them if required in single command.

First of all, list all files older than 30 days under /tmp directory.

We need to use the find command to get the all the files more than 30 days, As you wish and after that 1st we need to list out the files by following the given commands.

$ find /tmp/ -type f -mtime +30


To delete use the given command.

$ find /tmp -type f -mtime +30 -delete



2. Delete Files using Specific Extension


To delete specif extension files in linux, We need to add some more filters with find command, For a example we need to delete the .log extension and modified before 30 days, Use the following command for the same. 

Get the files with extension 1st 

$ find /var/log -name "*.log" -type f -mtime +30


To delete the extension files

$ find /var/log -name "*.log" -type f -mtime +30 -delete  

How to Delete old Files in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top