Delete files created 5 mins or earlier in a folder

Posted on

Delete files created 5 mins or earlier in a folder – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about linux, cron, files, rm, .

On CentOS, how can I delete files which are created 5 mins ago or earlier in a folder? Thanks!

Solution :

Try using find:

find ./ -mmin -5 -exec rm -i '{}' ;

Simmilar to kce:

find /path/to/folder -type f -cmin -5 -print0|xargs -r0 rm 

Added a search for files only and used cmin instead of mmin as you asked for files created in the past five minutes. I like to combine find with xargs.

In UNIX, we typically refer to them as directories, not folders. I used your name in the path above.

Leave a Reply

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