Delete / Remove a Directory Linux Command

by on June 8, 2006 · 98 comments· LAST UPDATED July 17, 2013

in , ,

I am a new Linux user. How do I delete or remove a directory using command line option?

You can use the following commands to delete the directory (also known as folder in the Macintosh OS X and Microsoft Windows operating system).

a] rmdir command - Deletes the specified empty directories.

Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Requirementsrmdir command
Estimated completion timeLess than a minute
b] rm command - Delete the file including sub-directories.

Syntax- rmdir command

The rmdir command remove the DIRECTORY(ies), if they are empty. The syntax is:

rmdir directory-name
rmdir [option] directory-name


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

rmdir: letters: Directory not empty

You can cd to the directory to find out files:
$ cd letters
$ ls

In this example, remove data, foo and bar if bar were empty, foo only contained bar and data only contained foo directories:

cd /home/nixcraft
rmdir -p data/foo/bar


  1. -p - 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.

Linux remove entire directory including all files and sub-directories command

To remove all directories and subdirectories use rm command. For example remove *.doc files and all subdirectories and files inside letters directory, type the following command (warning all files including subdirectories will be deleted permanently):
$ rm -rf letters/

  1. -r : Attempt to remove the file hierarchy rooted in each file argument i.e. recursively remove subdirectories and files from the specified directory.
  2. -f : Attempt to remove the files without prompting for confirmation, regardless of the file's permissions
See also
Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 98 comments… read them below or add one }

1 yogi April 28, 2008 at 3:24 am

very good
i give five star


2 Sourav August 2, 2012 at 7:36 am

Getting error as : Permission denied


3 Chris Lentz August 10, 2012 at 1:53 pm

Try running with ‘sudo’ command in front of it.


4 vishwa May 20, 2008 at 10:25 am

i tried it , very good can delete a large directory also.

i give 5 stars


5 Kshitiz Singh April 14, 2012 at 4:36 am

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


6 Mark October 7, 2012 at 6:03 pm

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.


7 Yury October 31, 2008 at 11:05 am

thank you


8 Arif November 6, 2008 at 5:06 am

Very effective


9 suveetha November 28, 2008 at 11:45 am



10 manjunath December 8, 2008 at 5:10 pm

thanks a lot


11 Ed December 10, 2008 at 9:27 am

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?


12 nixCraft December 10, 2008 at 9:34 am

Run rm as root. Otherwise use chmod -R to change permission.


13 Ed December 10, 2008 at 9:47 am

thanks for the reply Vivek


14 krishna February 7, 2009 at 10:32 am

thanks yaar really works


15 raja February 10, 2009 at 12:33 pm

Thanks for remove with sub directory cmd is rm -rf


16 ralph February 12, 2009 at 4:42 pm

Awesome! great!


17 ghan March 4, 2009 at 1:26 am

Save my time. Very useful. Thanks a lot!


18 nguyen ngoc thanh March 19, 2009 at 2:18 am

very good!


19 hari March 25, 2009 at 3:33 pm

Thanks ! its very useful.


20 phani March 30, 2009 at 9:13 am

thaks..a lot. i know the differnce between rmdir and rm -rf.


21 Nandlal Sahu April 1, 2009 at 10:21 am

i give 5 star


22 ganesh April 13, 2009 at 5:19 am

its very effective


23 Timon April 14, 2009 at 7:49 pm

Thank you is very usefull post :)


24 Jordan May 8, 2009 at 4:15 am

Thank u very much it works properly


25 Sukhdeep Singh July 14, 2009 at 12:51 pm

Thank You
Very very useful post sir


26 anad July 15, 2009 at 4:40 pm

worked for me


27 pravin August 7, 2009 at 6:08 am

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 !!!!!!!!!!!!!!


28 Max August 12, 2009 at 12:19 pm

very useful info ! Thanks


29 Draco August 14, 2009 at 11:11 pm

Thanks a lot! I needed it for work and didn’t want to take chance to mess sth up.


30 Juan Guillermo August 31, 2009 at 5:11 am

-r Stands for Recursive and -f Stands for Force

Take care with the effect when using ‘-rf’ flags


31 amit September 1, 2009 at 5:39 pm



32 traverlawre October 19, 2009 at 2:52 am

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.


33 Sujan November 24, 2009 at 5:08 am

Thanks traverlawre,
‘sudo’ did it. Without ‘sudo’ I had permission denied for many files that I wanted to remove.


34 Shady December 3, 2009 at 1:43 pm

excellent article


35 siropio December 7, 2009 at 2:28 pm

worked! thanks


36 d134 December 12, 2009 at 8:45 pm

thanx a lot


37 lalish February 3, 2010 at 5:56 am

its niceeeeee


38 Rajive March 10, 2010 at 8:01 am

Thanks a lot bro

Helped me a lot.


39 Tarun April 15, 2010 at 9:35 am

how to remove the directory with spaces.
rm -rf “file name”
it dosnt works.


40 kaptenvu June 23, 2010 at 6:44 am

try this :
rm -rf file\ name\ with\ spaces


41 Shabbir Ahmed June 24, 2010 at 9:53 am

I am installing oracle10 database on linux (rh4em) plz can i have the easiest steps taht first time i can understand.


42 Guru July 29, 2010 at 1:00 pm

Is any linux/unix command to delete one folder among 5 folders inside directory?
Thanks with anticipation


43 Balaraju/Aniruddh Divy Tej August 21, 2010 at 9:59 am

information is most use full thanks for your help
I appreciate your great help


44 Esonz August 23, 2010 at 5:27 am

Great! taynk yow!


45 Frederik August 26, 2010 at 12:04 pm

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…


46 random September 25, 2010 at 4:51 pm

Thanks a lot !!! very effective


47 dana October 30, 2010 at 1:48 am

You have been bailing me out countless of times. Thanks!


48 Miguel Costa November 9, 2010 at 10:56 am

:) tks a lot
You really helped me ;)


49 sandeep choudhary November 10, 2010 at 4:33 pm

i m unsetisfide


50 lara December 2, 2010 at 3:47 am

thanks 4 the nice idea about that!.. hehe


51 nagesh December 19, 2010 at 8:42 am

cool command…. simply works great,thanks


52 Rakesh January 4, 2011 at 5:51 am

Thank you


53 Pankaj January 27, 2011 at 5:36 am

Thanks…! it helps


54 Sivasangkari February 9, 2011 at 8:27 am

Thanks a lot…it’s very helpful…


55 Nisha March 31, 2011 at 4:14 am

Thanks a lot..


56 Duncan Murimi April 26, 2011 at 12:17 pm

Very useful. for permission denied folders add sudo in front.


57 Marco May 18, 2011 at 10:26 am

thanks! save me some time as im new to linux!


58 Terryble September 8, 2011 at 1:25 pm

rm -rf

will remove it without any answer needed.

rm -r without (-f for force) will request you a reply to remove each files.
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’?


59 Rahinur Rahaman September 14, 2011 at 3:20 am


It works for me


60 Nitin October 26, 2011 at 2:04 am

Thanks :)


61 Raghavendra November 16, 2011 at 7:34 am

Please guide me If i have mutipal folders in same dir.
ls -x
Now I want delete ..a c d dir.How can I delete in singal command


62 syamkumar December 21, 2011 at 6:03 am

Thanks its very useful.


63 harga laptop January 23, 2012 at 10:21 am

What’s the command to find all files with extension tmp (ex: *.tmp) and then delete them automatically? Thanks


64 n0de February 16, 2012 at 9:36 pm

very nice, worked like a charm keep up the good work ;)


65 Tirumal February 18, 2012 at 12:24 pm

Thanks for info…! It was really helpful


66 Shashank April 3, 2012 at 3:19 pm

thank a lot it’s working excellently


67 khalid April 26, 2012 at 10:19 pm

thanks a lot save my time


68 Yousefzad May 16, 2012 at 4:39 am

Thank you very Much for the information, i found it so useful.



69 Jacob July 3, 2012 at 1:29 pm

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?


70 Alireza July 13, 2012 at 12:35 pm

Thank you.


71 Onneile August 27, 2012 at 5:55 pm

Thanks, it worked for me


72 Syed Ahmed September 4, 2012 at 4:24 am

I have problem of Koha perl comiling…. when I put the command…. following …

sudo perl Makefile.PL
Can’t locate 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/ line 102.
BEGIN failed–compilation aborted at /koha-latest/koha-3.08.04/C4/ line 102.
Compilation failed in require at /koha-latest/koha-3.08.04/C4/ line 24.
BEGIN failed–compilation aborted at /koha-latest/koha-3.08.04/C4/ 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


Syed Ahmed


73 Mekbib September 10, 2012 at 7:17 am

Thanks i found it helpful.


74 Anoop September 11, 2012 at 5:27 am

It was really useful. Thank you


75 Varsha Katre September 15, 2012 at 10:43 am

Thank you very much!!! It worked!! :) :) :)


76 Amiya September 28, 2012 at 3:43 pm

nice one..very help full info..

i will give *****


77 Hamid October 15, 2012 at 7:20 am

دمت گرم اينم تو اونت
Thank you very much. It’s very good!


78 Julio November 1, 2012 at 7:26 pm

Thanks a lot, this was really helpful!


79 Martial Tchuente November 27, 2012 at 8:52 am

This definitely solved my problem.
I’m still a Linux newbie.


80 Nick January 3, 2013 at 3:42 pm

thank you so much I was about 30 seconds away from doing a hard restore on my iphone but luckily I found this forum first! I was desperate I could not find a way to remove my directory thanks to an archive that the program was unable to locate…the prgram was not installed but it was not complletely uninstalled and i could neither delete or load my cydia directory. Thanks so much!

Just on a side note…anyone know what to do now that the hackulous team has disassembled??


81 Tom G February 6, 2013 at 11:32 pm

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!


82 Elrafie March 16, 2013 at 8:38 pm

sudo rm -r /home/elrafie/recup_dir.1
sudo rm -r /home/elrafie/recup_dir.2


83 xyz July 17, 2013 at 7:13 am

it worked…:)


84 mydhili warrier July 25, 2013 at 7:42 am

thank u soooooo muchhhhhhhhh…:)its working…:) :) :)
can anyone plzz help me with this..?? i need to change my directory and the dir name contains 3 words separated by spaces.. like “whole Project Mydhili”. I tried

cd whole Project Mydhili

but the result was :there is no such file or directory”. My path to the dir is correct and when i gave an ls command ,i can see this dir in the list…but am not able to make it as my pwd..!! i tried as super user (sudo) too..
plzz if u could help me,i will b so thaankful to u.


85 Uncle December 7, 2013 at 2:04 pm

Thanks Helpful Stuff


86 chatu January 29, 2014 at 5:31 am

to remove all the content in a dir

commad :: rm -rf *


87 chatu January 29, 2014 at 5:31 am

to remove all the content in a dir

commad :: rm -rf *


88 Jai Prakash Yadav March 3, 2014 at 12:40 pm

I want to remove folder , pls suggest which command i can use..


89 Nik March 19, 2014 at 3:43 pm

Thank you !!


90 Charlie May 15, 2014 at 11:03 pm

here is another:
mv folder /tmp


91 felisbag January 22, 2015 at 9:34 am

Yes, it works. Thanks.


92 Venkat July 13, 2014 at 9:10 pm


I have created a .trash hidden directory to get the removed files to use as recyclic bin by using the below command
alias rm=’mv\!*~/.trash’
Now I could not use rm -rf or rmdir command.

Error message is coming as
:bash= mv\!*~/.trash : directory or file not found.
Can anyone please help me? in this. It will be very helpful to me.


93 Ranjeet July 14, 2014 at 3:26 pm


I’m trying to delete a directory Test2(e.g.: /home/apps/Test/Test1/Test2 by executing sh script.

cd /home/apps/Test/Test1
rm -rf Test2

But if Test2 directory is already deleted then it throws error. I want to proceed further even if Test2 is not present. Can some one please help me out?


94 Ramlee August 6, 2014 at 1:12 am

Yesterday, I incorrectly extracted a soundfont to the following location : /usr/share/sounds/sf2/GeneralUser GS 1.44 FluidSynth.
I would like to delete that last folder completely along with all contents and then install the soundfont correctly. I’ve tried almost every combination of the command line codes given above (rm -rf) but nothng seems to happen. I suspect I’m not typing in the command correctly. Any help would be appreciated.

Regards Ramlee.


95 shivaji September 11, 2014 at 8:32 am

Thank you for the guidance.


96 juvy October 2, 2014 at 11:55 am

what is the command on how to create and delete a folder in cent os 6 ? pls ans. thanks :)


97 Mozah Chisanger November 26, 2014 at 6:34 am

This so nice. Thank you!


98 Francesco February 27, 2015 at 12:50 pm

Hi, I have a problem with this command :

A file that contain “è” is recognised as “??” and when I try to delete it with the rm command (or rm -rf) I get the following error :

rm: cannot remove ‘Wolf – La Belva ?? Fuori – 1994.avi': No such file or directory

Its not a directory but an avi file

tried with the following :

rm 'Wolf - La Belva ?? Fuori - 1994.avi'
rm -r 'Wolf - La Belva ?? Fuori - 1994.avi'
rm ./"Wolf - La Belva ?? Fuori - 1994.avi"
rm -rf ./"Wolf - La Belva ?? Fuori - 1994.avi"

nothing works :(

Can someone please help me to find the correct command ? Thank you so much!



Leave a Comment

Tagged as: , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: