Delete command crashed my server


New Member
Dec 22, 2019
Reaction score
i ran the following command find /tmp/ -type f -mtime +2 -exec rm -f {} \; on my centos server to try and create some free space. after i ran this command my server crashed. i had to restore from a backup VM. This command has worked before on some of my servers. what could have gone wrong?

You are selecting and deleting files from /tmp/ based on their modification time-stamp - but because this is a server we're talking about - it is possible that a process could have written to the file two or more days ago, but it could still periodically be reading/accessing that data-file - without modifying it. That's one possibility - a process crashing because it cannot find data that it relied upon.

So perhaps selecting files based on their atime (last accessed time) instead of their mtime would make more sense? - so only delete a file if it hasn't been accessed in more than two days? Perhaps?!

Also, I'm not certain about the effect of using the -f (force) flag in your rm command.
I can't remember if rm -f will fail to delete a file, if the file is already in use by a running process. Or if it will just go ahead and remove the file anyway. But hypothetically - if rm -f can delete files that are already open - that would almost certainly cause a process to crash too, if the data file it was using suddenly becomes unavailable. Unfortunately, I don't have time ATM to try to test my rm -f hypothesis!

But the problem is definitely related to one of these factors.... Or perhaps both (if my rm -f hypothesis is correct).

Members online

Latest posts