How to remove all files that were created n minutes ago in linux

Solution 1:

I wonder what man find would say. Then you can even show your efforts.

find . -type f -cmin -1
find . -type f -cmin -1 -delete
  • The -type f is used to specify only regular files are selected.
  • The -cmin -1 the file's status was last changed in less than the past (one) minute.
  • The -delete flag tells find to deletes all your electronics files in the known universe or something like that, so use caution when using it.

First doing a test run without the -delete flag is strongly recommended.

Note -delete is a non-portable extension.

I recommend reading the find manpage before using this, because it covers various gotchas and warnings that may apply in your situation.

Solution 2:

find . -mtime -60s -exec mv {} /dest/dir \;

Finds every file in the current directory (and sub directories) that has been modified in the last 60 seconds and move them to /dest/dir.