I am using Nextcloud and since the "retention" app is still not working on v20 I try to code an autodelete script for myself.

The problem is, when I upload files to the Nextcloud share the original creation date of the file is kept. Only the "change" and the "access" times are changed by the upload, when I look at "stat file.txt" for example.

I want the script to automatically delete all files which are uploaded more than two weeks ago from the current date/time independent of the original creation date of the file.

Any hints how I can search or list files with the criterion from above?

1 Answer 1


You can use find with mtime/ctime/atime for time of modification, metadata change or access and +14 for two weeks.

find <path> -type f -ctime +14 -delete

(I suggest testing this first with -print instead of -delete to make sure it works correctly.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .