Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Up until now I was using Ubuntu, and the behaviour of rm for directories was the following:

  • rm -r dir would remove dir if it was empty, and give an error otherwise
  • rm -rf dir would remove dir and its contents recursively

It's possible that rm was aliased to something to behave this way, but I no longer have access to my Ubuntu system so I can't tell.

Now I switched to Linux Mint, and the behaviour is different: rm -r removes a directory and its contents recursively, just like rm -rf did on Ubuntu.

I looked at rm's manpage on Linux Mint to try to find a combination of options that would reproduce the Ubuntu behaviour, but I couldn't find any.

My questions are:

  • Why is the behaviour of rm different between Linux distributions? Isn't it a standard tool that should be the same everywhere?
  • How do I achieve the behaviour described at the beginning of the question?
share|improve this question
This is nonstandard behavior for rm. I have never had rm behave this way on Ubuntu, Red Hat, SuSE, or any other mainstream distro that I've used. Are you sure you weren't using rmdir instead? – rob Aug 1 '13 at 21:47
@rob: Quite sure. I will investigate next time I'm at a Ubuntu system with this behaviour. – HighCommander4 Aug 1 '13 at 22:29

It could be possible that rm was aliased to something on your Ubuntu system (in .bashrc, for example). rm -r deletes the dir and it's contents for me on Ubuntu 12.04. rm -f needs to be used for cases where there are different permissions on the content of the dir (for example, read-only files).

share|improve this answer
Do you have any idea of what rm might have been aliased to on my Ubuntu system to get the behaviour I described? I looked at man rm on my Linux Mint system but couldn't find any options that would yield that behaviour. – HighCommander4 Aug 1 '13 at 20:37
What error did you get when you ran rm -r <dir> on a directory with content inside it? – Gurkaran Singh Aug 1 '13 at 20:41
The error was: rm: cannot remove '<dir>': Directory not empty. – HighCommander4 Aug 1 '13 at 20:44
Perhaps it could have been a filesystem error on your Ubuntu machine? See:… and… – Gurkaran Singh Aug 1 '13 at 20:52
I think default behavior is only to throw that error if a file is in use. – Raystafarian Aug 1 '13 at 21:08

Use the rmdir command, it will only remove empty directories

share|improve this answer

You must log in to answer this question.

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