Efficient and quick way to delete files! - Bash

On the sidelines of previous post "An efficient and quick way to search with find, grep, and xargs", I've just remembered one of servers has an issue with sessions garbage collection! So, after a while the monitoring system detected unusual decrease in free disk space. And after I got a look, I found sessions directory has about 32 million file :D

As I mentioned in the other post, normal tools aren't designed to work with huge number of files like that, so to deal with this especially in regard to "disk IO" and "CPU utilization" in production environment, "find" was the best solution to delete that huge number of files.

Actually, this time you will not need an external command like "rm" or so, "find" itself has an option called "-delete", which can be used to delete files:
find PATH -type f -name "FILES_PATTERN" -delete
That's why I love "find", it's very powerful and has many great options. It always save my time, I did a lot of cool things just with find!
Powered by Blogger.

Hello, my name is Ahmed AbouZaid and this is my "lite" technical blog!

I'm a passionate DevOps engineer, Cloud/Kubernetes specialist, Free/Open source geek, and an author.

I believe in self CI/CD (Continuous Improvements/Development), also that "the whole is greater than the sum of its parts".

DevOps transformation, automation, data, and metrics are my preferred areas. And I like to help both businesses and people to grow.

Latest Post

🔀Merger🔀, a schemaless strategic merge plugin - Kustomize

Kustomize is a great tool. I've been using Kustomize for almost 4 years and am happy with it. However, it's ...

Popular Posts

Blog Archive