In Unix, how do I remove a directory?

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

Latest Articles

Replies:

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <b> <bdo> <blockquote> <br> <code> <dd> <dl> <dt> <em> <i> <li> <ol> <ul> <img> <strong>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

Image CAPTCHA
Enter the characters (without spaces) shown in the image.