3

When I try rm -rf on a directory which has a lot of subdirectories and/or files and which is mounted with SSHFS, then I takes a while to execute.

Is it normal ?

I would like to know how rm -rf works internally, at the Files System level.

Does it only remove the directory, or does it go through all directory/files ? That would explain why it so slow...

5
  • When I read the title "How works rm -rf? I hear Yoda's voice as the narrator. :-) Jul 3, 2012 at 18:25
  • You may be able to speed up the removal by ssh-ing into the remote system and executing the rm -rf there. Jul 3, 2012 at 19:34
  • @Somantra: Sorry that's the french sentence construction :p
    – Charles
    Jul 3, 2012 at 20:54
  • @BrianSwift Thanks for the tips, that's exactly what I did. I just wanted to be sure that I correctly understand the problem.
    – Charles
    Jul 3, 2012 at 20:54
  • @Somantra: I get an Insane Clown Posse vibe, myself.
    – womble
    Jul 4, 2012 at 6:00

2 Answers 2

6

The -r switch acts exactly how its name implies: recursively. It executes the same action on each and every file and directory inside the current directory, before removing it.

So, yes, being quite slow for large (as in "with lots of different things inside") directories is absolutely normal.

One of the biggest (and most feared) signs you mistyped a rm -rf command and are actually destroying your root partition is an overly long execution time...

2
  • 2
    @charles And it's going to be even worse with the sshfs that you mentioned, as you'll be adding in network latency, on top of any disk latency the server is experiencing while executing the rm.
    – cjc
    Jul 3, 2012 at 18:44
  • that's my problem :p
    – Charles
    Jul 3, 2012 at 20:56
2

Yes, the command is recursive.

From man rm

-r, -R, --recursive

remove directories and their contents recursively

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .