How to delete files that were created a few days ago on Linux?

To delete files from a Linux system that were created a few days ago, you can use the find command with the -mtime parameter. The -mtime parameter is used to specify the modification time of the file and can be used to search for files based on days.

Here is an example command for deleting files from 7 days ago:

find /path/to/directory -mtime +7 -type f -delete

This command will search for files in the specified directory that were last modified more than 7 days ago and delete them. Make sure to replace /path/to/directory with the actual directory path. If you want to delete folders instead of files, you can replace -type f with -type d. If you only want to search for files without deleting them, you can remove the -delete parameter.

In addition, deleting files is a risky operation, so use it with caution and make sure you know what you’re doing.

Leave a Reply 0

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