-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
  • 731
  • 2
  • 7
  • 13
  • 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 01 '13 at 21:47
  • @rob: Quite sure. I will investigate next time I'm at a Ubuntu system with this behaviour. – HighCommander4 Aug 01 '13 at 22:29

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

  • 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 01 '13 at 20:37
  • What error did you get when you ran `rm -r ` on a directory with content inside it? – Gurkaran Singh Aug 01 '13 at 20:41
  • The error was: `rm: cannot remove '': Directory not empty`. – HighCommander4 Aug 01 '13 at 20:44
  • Perhaps it could have been a filesystem error on your Ubuntu machine? See: http://superuser.com/questions/383221/how-do-i-delete-a-directory-that-appears-to-contain-nameless-files and http://www.linuxquestions.org/questions/linux-general-1/rm-cannot-remove-directory-%60ff'-directory-not-empty-298105/ – Gurkaran Singh Aug 01 '13 at 20:52
  • No, I only got that message if the directory was in fact not empty. – HighCommander4 Aug 01 '13 at 21:01
  • 1
    I think default behavior is only to throw that error if a file is in use. – Raystafarian Aug 01 '13 at 21:08
1

Use the rmdir command, it will only remove empty directories

Raystafarian
  • 21,583
  • 11
  • 60
  • 89