4

What is the difference between rm --dir <directory> and rmdir <directory> with respect to removing empty directories?

Also, if they are similar, is there any advantage of having an rmdir command considering that it is limited only to the removal of empty directories and that the rm command can achieve the same functionality (and a lot more) with its numerous options?

1

rmdir removes empty directories, not files, and not directories unless they are empty.

rm will remove files and/or directories, use the -R or -r flag for directories.

To remove non-empty directories: rm -rf

the option --dir is the same as -d , it will remove empty directories, same as rmdir

As far as I know the commands do the same thing and it is user preference which one you use, personally, I use

rm -rf

I also alias rm to rm -i

Careful with that command. It is unforgiving if you make a mistake, especially when combined with sudo (which is why I alias it to rm -i, the -f overrides the -i).

I suppose rmdir might be safer in that it will not remove a directory unless it is empty first, forcing you to review the contents first.

| improve this answer | |
  • 1
    +1 for the answer. However, the question is about the difference between rm --dir and rmdir for removing empty directories. Have edited the question title accordingly. – Rohith Madhavan Dec 17 '14 at 23:33
  • Other then the name of the command and options (rm has more options then rmdir) there is no difference. – Panther Dec 18 '14 at 2:03
  • I also found the two commands to have the same functionality which made me wonder - "What is the need for rmdir when rm --dir does the same thing?" The fact that the same author has written both the commands is puzzling. – Rohith Madhavan Dec 18 '14 at 11:23
  • I suggest you ask the author, you are sort of moving beyond Ubuntu support and into conjecture. One advantage on Linux, there are often at least 2 ways of accomplishing various tasks. – Panther Dec 18 '14 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.