How to find and delete files in Linux older than 30 days. Here is the terminal command to find and delete files recursively Linux.
You can easily find and remove multiple files with the extension or delete files older than 7 days in Linux.
Find and Delete Files Older Than X Minutes
Run the following commands to find to delete files which are older than 15 minutes:
find . -name "example*.txt" -type f -mmin +15 -delete
In this above command, the file name is prefixed with the -name option and -type f means we want to find for files only. The -mmin stands for the modification time in minutes and +15 means we want to find files that were last modified 15 minutes ago or earlier than the specified time.
Find and Delete Files Older Than 30 Days
Run the following commands to find to delete files which are older than 30 days:
find . -name "example*.txt" -type f -mtime +5 -delete
Note that the -mtime option specifies to run the find command and to delete files that were modified at least 5 days ago.
Find and Delete Files Recursively Linux
To find and delete files recursively in Linux, we will use the rm command. It is so because the -delete option may fail if the directory is not empty.
Simply run the find command to search for the specific file and then use rm command to delete:
find /Downloads/Images -type d -mtime +90 find /Downloads/Images -type d -mtime +30 -exec rm -rf {} \;
Find and Delete Files With .mp4 Extension
To find and delete files with a specific extension, simply specify the extension with the file name to be searched.