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/
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 81 comments… read them below or add one }
very good
i give five star
Getting error as : Permission denied
Try running with ‘sudo’ command in front of it.
i tried it , very good can delete a large directory also.
i give 5 stars
I give it a 3 star. There has to be a more flexible way to do it. Removing files permanently is not a good option for linux this is a windows kind of rubbish thing
It’s not exactly permanent in Windows either. In fact, the “undelete” command has been available for quite some time… the Recycle Bin/Trash makes it possible to restore in both operating systems (from the GUI of course). I’m not exactly glorifying M$ but they aren’t exactly the cesspool of operating systems… LOL they’re not the best either but if M$ Windows were FREE and/or Open it may change some opinions.
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
very nice, worked like a charm keep up the good work ;)
Thanks for info…! It was really helpful
thank a lot it’s working excellently
thanks a lot save my time
Thank you very Much for the information, i found it so useful.
thanks,
Is there a way to delete like every directory named a special name if so I have 19 directorys with the same name on my dedicated debian server and I want to delete all of them then it just searches for the names and deletes them?
Thank you.
Thanks, it worked for me
I have problem of Koha perl comiling…. when I put the command…. following …
sudo perl Makefile.PL
Can’t locate ZOOM.pm in @INC (@INC contains: /koha-latest/koha-3.08.04 /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at /koha-latest/koha-3.08.04/C4/Context.pm line 102.
BEGIN failed–compilation aborted at /koha-latest/koha-3.08.04/C4/Context.pm line 102.
Compilation failed in require at /koha-latest/koha-3.08.04/C4/Installer.pm line 24.
BEGIN failed–compilation aborted at /koha-latest/koha-3.08.04/C4/Installer.pm line 24.
Compilation failed in require at Makefile.PL line 31.
BEGIN failed–compilation aborted at Makefile.PL line 31.
Then showing this command
What to do now… Pls give me …. msg
Thanks.
Syed Ahmed
Thanks i found it helpful.
It was really useful. Thank you
Thank you very much!!! It worked!! :) :) :)
nice one..very help full info..
i will give *****
دمت گرم اينم تو اونت
Thank you very much. It’s very good!
Thanks a lot, this was really helpful!
This definitely solved my problem.
I’m still a Linux newbie.
Thanks!
Thanks a lot!
Another tip: you can use wildcards to remove many folders which have the same name at the start, E.G to remove all the folders “recup_dir.1″ , “recup_dir.2″, “recup_dir.3″
I would type ” sudo rm -rf recup_dir*** ” and all the folders disappear :) This was very useful as a file ‘undeleter’ left me with loads of these folders!
sudo rm -r /home/elrafie/recup_dir.1
sudo rm -r /home/elrafie/recup_dir.2