Q. Can you tell me command to delete a directory in terminal?
A. You need to use the rmdir utility / command. The rmdir utility removes the directory entry specified by each directory argument, provided it is empty. Arguments are processed in the order given. In order to remove both a parent directory and a subdirectory of that parent, the subdirectory must be specified first so the parent directory is empty when rmdir tries to remove it.
Remove / Delete directory called /tmp/foo
Open the terminal. Type the following command:
$ rmdir /tmp/foo
Recursive removal
Remove all files and directories (recursive removal):
$ rm -rf /path/to/directory
$ rm -rf /tmp/foo
Please note that you can also pass -p option to rmdir command. Each directory argument is treated as a pathname of which all components will be removed, if they are empty, starting with the last most component:
$ rmdir -p /tmp/x/y/z
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- My 10 UNIX Command Line Mistakes
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
- Email FAQ to a friend
- Download PDF version
- Printable version
- Comment RSS feed
- Last Updated: 10/24/07



{ 4 comments… read them below or add one }
Thanks for this. However, it doesn’t always work. I found that Thunderbird stores a hidden file in a /home directory and I kept getting a message saying that the folder was not empty. In the end, I used “gksudo nautilus”, renamed the hidden file and then deleted it.
tnx for this
It really works thanks
I really doesn’t work. I get the error message saying rmdir: invalid option — ‘r’ when i put in the following:
rmdir -r /sametime-connect-8.0.2/opt/ibm/lotus/sametime/eclipse/plugins/org.apache.lecene_1.4.103.v20060601/META-INF