Technology

#How to Find or Delete Files Less Than X Minutes Old on Linux – CloudSavvy IT

“#How to Find or Delete Files Less Than X Minutes Old on Linux – CloudSavvy IT”

Bash Shell

Say you just ran some script that was supposed to move files around or download stuff, or anything else that involves files, and then you realize that you need to figure out what files just got created and where. And maybe you need to delete them.

First you’ll want to use the find command to figure out what files were created, and then using the mmin argument to specify files less than x minutes. If you want to specify only files, you can use the -type f argument to only check for files.

So if you want to check in the current folder, including subfolders, for files created in the last 5 minutes, you can use the following command:

find ./ -type f -mmin -5

To delete files we can use the -exec rm {} ; argument, which is a little confusing, but basically you’re telling the exec argument to remove the files.

So to delete all files in the current folder, including subfolders, created in the last 5 minutes, use this command:

find ./ -type f -mmin -5 -exec rm {} ;

If you wanted to specify files older than X days instead, you could use the -mtime argument — for instance, this command would delete files older than 10 days:

find ./ -type f -mtime +10 -exec rm {} ;

Much easier than looking at the man page.

If you liked the article, do not forget to share it with your friends. Follow us on Google News too, click on the star and choose us from your favorites.

For forums sites go to Forum.BuradaBiliyorum.Com

If you want to read more like this article, you can visit our Technology category.

Source

Related Articles

Leave a Reply

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

Back to top button
Close

Please allow ads on our site

Please consider supporting us by disabling your ad blocker!