Delete / Remove a Directory Linux Command

by Vivek Gite on June 8, 2006 · 59 comments

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:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 59 comments… read them below or add one }

1 yogi April 28, 2008

very good
i give five star

Reply

2 vishwa May 20, 2008

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

i give 5 stars

Reply

3 Yury October 31, 2008

thank you

Reply

4 Arif November 6, 2008

Very effective

Reply

5 suveetha November 28, 2008

THANKS:)

Reply

6 manjunath December 8, 2008

thanks a lot

Reply

7 Ed December 10, 2008

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?

Reply

8 Vivek Gite December 10, 2008

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

Reply

9 Ed December 10, 2008

thanks for the reply Vivek

Reply

10 krishna February 7, 2009

thanks yaar really works

Reply

11 raja February 10, 2009

Thanks for remove with sub directory cmd is rm -rf

Reply

12 ralph February 12, 2009

Awesome! great!

Reply

13 ghan March 4, 2009

Save my time. Very useful. Thanks a lot!

Reply

14 nguyen ngoc thanh March 19, 2009

very good!

Reply

15 hari March 25, 2009

Thanks ! its very useful.

Reply

16 phani March 30, 2009

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

Reply

17 Nandlal Sahu April 1, 2009

Excellent
i give 5 star

Reply

18 ganesh April 13, 2009

its very effective

Reply

19 Timon April 14, 2009

Thank you is very usefull post :)

Reply

20 Jordan May 8, 2009

Thank u very much it works properly

Reply

21 Sukhdeep Singh July 14, 2009

Thank You
Very very useful post sir

Reply

22 anad July 15, 2009

worked for me

Reply

23 pravin August 7, 2009

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

Reply

24 Max August 12, 2009

very useful info ! Thanks

Reply

25 Draco August 14, 2009

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

Reply

26 Juan Guillermo August 31, 2009

-r Stands for Recursive and -f Stands for Force

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

Reply

27 amit September 1, 2009

thanks……….

Reply

28 traverlawre October 19, 2009

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.

Reply

29 Sujan November 24, 2009

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

Reply

30 Shady December 3, 2009

excellent article

Reply

31 siropio December 7, 2009

worked! thanks

Reply

32 d134 December 12, 2009

thanx a lot

Reply

33 lalish February 3, 2010

its niceeeeee

Reply

34 Rajive March 10, 2010

Thanks a lot bro

Helped me a lot.

Reply

35 Tarun April 15, 2010

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

Reply

36 kaptenvu June 23, 2010

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

Reply

37 Shabbir Ahmed June 24, 2010

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

Reply

38 Guru July 29, 2010

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

Reply

39 Balaraju/Aniruddh Divy Tej August 21, 2010

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

Reply

40 Esonz August 23, 2010

Great! taynk yow!

Reply

41 Frederik August 26, 2010

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…

Reply

42 random September 25, 2010

Thanks a lot !!! very effective

Reply

43 dana October 30, 2010

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

Reply

44 Miguel Costa November 9, 2010

:) tks a lot
You really helped me ;)

Reply

45 sandeep choudhary November 10, 2010

i m unsetisfide

Reply

46 lara December 2, 2010

thanks 4 the nice idea about that!.. hehe

Reply

47 nagesh December 19, 2010

cool command…. simply works great,thanks

Reply

48 Rakesh January 4, 2011

Thank you

Reply

49 Pankaj January 27, 2011

Thanks…! it helps

Reply

50 Sivasangkari February 9, 2011

Thanks a lot…it’s very helpful…

Reply

51 Nisha March 31, 2011

Thanks a lot..

Reply

52 Duncan Murimi April 26, 2011

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

Reply

53 Marco May 18, 2011

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

Reply

54 Terryble September 8, 2011

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’?

Reply

55 Rahinur Rahaman September 14, 2011

Thanks!

It works for me

Reply

56 Nitin October 26, 2011

Thanks :)

Reply

57 Raghavendra November 16, 2011

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

Reply

58 syamkumar December 21, 2011

Thanks its very useful.

Reply

59 harga laptop January 23, 2012

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

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 12 + 8 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: