With this, you will be able with the Linux find command to find all files older than 30 days and then execute rm command on them.

The find utility on Linux allows you to pass in arguments, including one to execute another command on each file. We’ll use this in order to figure out what files are older than a certain number of days, and then

use the ls command to list them. To be on the safe side and the

rm command to remove them.

List:

find  /path/to/files* –mtime +30 -exec ls –tl {} \;

Note that there are spaces between ls, {}, and \;

Remove:

find  /path/to/files* –mtime +30 -exec rm {} \;

  1. The first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.
  2. The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +30, it will find files older than 30 days
  3. The third argument, -exec, allows you to pass in a command such as ls -tl. The {} \; at the end is required to end the command.

Leave a Reply

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