-1

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?
HighCommander4
  • 771
  • 2
  • 7
  • 13

2 Answers2

1

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).

1

Use the rmdir command, it will only remove empty directories

Raystafarian
  • 21,963
  • 12
  • 64
  • 91