I am new to Linux and command line. How do I delete or remove a directory?
Use the rmdir command. This command remove the DIRECTORY(ies), if they are empty. Open a command-line terminal (select Applications > Accessories > Terminal), and then type the following command to remove a directory called /tmp/docs:
rmdir /tmp/docs
If a directory is not empty you will get an error:
$ rmdir letters
Output:
rmdir: letters: Directory not empty
You can cd to the directory to find out files:
$ cd letters
$ ls
Linux Remove Entire Directory Command
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 (warning all files including subdirectories will be deleted permanently):
$ rm -rf letters/
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- My 10 UNIX Command Line Mistakes
- Linux: 20 Iptables Examples For New SysAdmins

- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- 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
Facebook it - Tweet it - Print it -


{ 59 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.
how to remove the directory with spaces.
rm -rf “file name”
it dosnt works.
try this :
rm -rf file\ name\ with\ spaces
Hello!
I am installing oracle10 database on linux (rh4em) plz can i have the easiest steps taht first time i can understand.
Is any linux/unix command to delete one folder among 5 folders inside directory?
Thanks with anticipation
information is most use full thanks for your help
I appreciate your great help
Great! taynk yow!
Thanx seems to be very useful however I’m using Slax to access a damaged NTFS drive and am having trouble deleting files from that drive, i can read the files fine however i can’t change permissions for any of the files or folders and the drive is mounted with the ntfs -3g command so it should be editable. i’ve tried the chmod command without luck. any ideas?
Thanks a ton in advance…
Thanks a lot !!! very effective
You have been bailing me out countless of times. Thanks!
:D
:) tks a lot
You really helped me ;)
i m unsetisfide
thanks 4 the nice idea about that!.. hehe
cool command…. simply works great,thanks
Thank you
Thanks…! it helps
Thanks a lot…it’s very helpful…
Thanks a lot..
Very useful. for permission denied folders add sudo in front.
thanks! save me some time as im new to linux!
rm -rf
will remove it without any answer needed.
rm -r without (-f for force) will request you a reply to remove each files.
exemple:
rm -r ntop-4.1.0
rm: descend into directory `ntop-4.1.0′? yes
rm: remove regular file `ntop-4.1.0/ntop_win32.h’?
Thanks!
It works for me
Thanks :)
Please guide me If i have mutipal folders in same dir.
like
ls -x
a
b
c
d
f
Now I want delete ..a c d dir.How can I delete in singal command
Thanks its very useful.
What’s the command to find all files with extension tmp (ex: *.tmp) and then delete them automatically? Thanks