

Here we can execute the rm command using -exec command line option. The below command will search all directories modified before 90 days under the /var/log directory. In that case we will use Linux rm command with find command. Using the -delete option may fail, if the directory is not empty. log extension and last modification date is older than 30 days. Once the list is verified, delete those file by running the following command: find /var/log -name "*.log" -type f -mtime +30 -deleteĪbove command will delete only files having. find /var/log -name "*.log" -type f -mtime +30 For example, you only need to delete files with “.log” extension and modified before 30 days.įor the safe side, first do a dry run and list files matching the criteria. Instead of deleting all files, you can also add more filters to find command. find /opt/backup -type f -mtime +30 -delete 2. Once confirmed, you are good to go to delete those files with following command. Verify the file list and make sure no useful file is listed in above command. And also delete them if required in single command.įirst of all, list all files older than 30 days under /opt/backup directory. You can use the find command to search all files modified older than X days. Here 30 days older means the last modification date is before 30 days. This article describe you to how to find and delete files older than 30 days. To do it you can find older files from the backup directory and clean them. For example, if we are running daily/hourly backup of files or database on the server then there will be much junk created on the server. This is the best practice to remove old unused files from your server.
