02/10/2015

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, Linux system administrator, RedHat Certified Engineer (RHCE), AWS SysOps/Solutions Architect, Free/Open source geek, author, interested in environment, calligraphy, and I believe that “Details Matter”!

Automation, data, and metrics are my preferred areas. I have a built-in monitoring chip, and too lazy to do anything manually :D

Popular Posts