Delete Old Linux Files by Age
To delete files from a specific number of days, you can use the find command with the -exec option. Here is an example command:
find /path/to/directory -type f -mtime +30 -exec rm {} \;
In this command:
- The “path/to/directory” indicates the directory path from where files need to be deleted.
- Type “f” means to only delete files, excluding directories.
- -mtime +30: This indicates deleting files that were last modified more than 30 days ago. You can modify the number to specify the desired number of days.
- -exec rm {} \;: means to execute the rm command on the found files to delete them.
Please be extra careful when using this command to ensure that you are deleting the correct files and to avoid irreversible loss.