ARCHIVED: In Unix, how do I remove a directory?

This content has been archived, and is no longer maintained by Indiana University. Information here may no longer be accurate, and links may no longer be available or reliable.

To remove a directory that you own, use the rmdir command. For example, to remove a subdirectory named mydir that exists in your current working directory, at the Unix prompt, enter:

  rmdir mydir

If mydir exists, and is an empty directory, it will be removed. If the directory is not empty or you do not have permission to delete it, you will see an error message.

To remove a directory that is not empty, use the rm command with the -r option for recursive deletion. Be very careful with this command, because using the rm -r command will delete not only everything in the named directory, but also everything in its subdirectories. If you don't use this command very cautiously, you risk deleting all or most of your files.

If the subdirectory mydir exists in your current directory and it is not empty, you can delete it by entering at the Unix prompt:

  rm -r mydir

For more information on the rmdir and the rm -r commands, see their man pages. At the Unix prompt, enter:

  man rmdir

This is document abet in the Knowledge Base.
Last modified on 2018-01-18 08:51:27.