Q. I am new to Linux and command line. How do I delete or remove a directory?
A. Use rmdir command. This command remove the DIRECTORY(ies), if they are empty. For example, type the following command to remove /tmp/docs directory:
$ rmdir /tmp/docs
If directory is not empty you will get an error:
$ rmdir letters
Output:
rmdir: letters: Directory not empty
You can change directory to find out files:
$ cd letters
$ ls
Linux remove entire directory
To remove all directories and subdirectories use rm command. For example remove letters and all subdirectories and files inside this directory, type the following command:
$ rm -rf letters/
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: 04/4/09



{ 34 comments… read them below or add one }
very good
i give five star
i tried it , very good can delete a large directory also.
i give 5 stars
thank you
Very effective
THANKS:)
thanks a lot
rm: cannot remove `unixODBC//exe/.libs/odbcinst’: Permission denied
I got loads of these messages, must I go through each file and change their permissions?
Run rm as root. Otherwise use chmod -R to change permission.
thanks for the reply Vivek
thanks yaar really works
Thanks for remove with sub directory cmd is rm -rf
Awesome! great!
Save my time. Very useful. Thanks a lot!
very good!
Thanks ! its very useful.
thaks..a lot. i know the differnce between rmdir and rm -rf.
Excellent
i give 5 star
its very effective
Thank you is very usefull post :)
Thank u very much it works properly
Thank You
Very very useful post sir
worked for me
Hello all
i am having some trouble in deleting a directory in ubuntu. actually my directory’s ownership changes to ?? ?? also file size is also changed to ?? only name is there and all things changes to ?? like this,
ls: cannot access pg_database: No such file or directory
total 0
-????????? ? ? ? ? ? pg_database
I need your suggestions
Thanks in advance !!!!!!!!!!!!!!
very useful info ! Thanks
Thanks a lot! I needed it for work and didn’t want to take chance to mess sth up.
-r Stands for Recursive and -f Stands for Force
Take care with the effect when using ‘-rf’ flags
thanks……….
In Linux correct command would be rm -rf /letters/
The slash before the directory name is required or else it will not be seen as a directory and you will get an error. Also, consider using sudo such as:
sudo rm -rf /letters/ when permissions conflict.
Thanks traverlawre,
’sudo’ did it. Without ’sudo’ I had permission denied for many files that I wanted to remove.
excellent article
worked! thanks
thanx a lot
its niceeeeee
Thanks a lot bro
Helped me a lot.