Skip to content
Advertisement

Deleting files after 7 days not working

I am trying to delete all files that are older than 7 days. The command is working but not correctly.

JavaScript

It does delete files but it’s not accurate.

JavaScript

The find does delete files, but when I run the ls command does contain files that should be deleted. For example today is November 7th. The find should delete all files before November 1st. It does not. The command leaves files that are in October 30 and 31. How can I delete files that are older than 7 days.

If I run find command like 3 minutes later. It deletes files with the date of October 30 and a time of 3 minutes after it first ran.

Advertisement

Answer

From man find:

JavaScript

This means that your command actually deletes files that were accessed 8 or more days ago.

Since the time now is

JavaScript

find will require files need to be older than:

JavaScript

In other words, leaving some files from Oct 30 is expected and documented behavior.

To account for find rounding down, simply use -mtime +6 instead.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement