Delete / Remove a Directory Linux Command

by Vivek Gite · 34 comments

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:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 34 comments… read them below or add one }

1 yogi 04.28.08 at 3:24 am

very good
i give five star

2 vishwa 05.20.08 at 10:25 am

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

i give 5 stars

3 Yury 10.31.08 at 11:05 am

thank you

4 Arif 11.06.08 at 5:06 am

Very effective

5 suveetha 11.28.08 at 11:45 am

THANKS:)

6 manjunath 12.08.08 at 5:10 pm

thanks a lot

7 Ed 12.10.08 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?

8 Vivek Gite 12.10.08 at 9:34 am

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

9 Ed 12.10.08 at 9:47 am

thanks for the reply Vivek

10 krishna 02.07.09 at 10:32 am

thanks yaar really works

11 raja 02.10.09 at 12:33 pm

Thanks for remove with sub directory cmd is rm -rf

12 ralph 02.12.09 at 4:42 pm

Awesome! great!

13 ghan 03.04.09 at 1:26 am

Save my time. Very useful. Thanks a lot!

14 nguyen ngoc thanh 03.19.09 at 2:18 am

very good!

15 hari 03.25.09 at 3:33 pm

Thanks ! its very useful.

16 phani 03.30.09 at 9:13 am

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

17 Nandlal Sahu 04.01.09 at 10:21 am

Excellent
i give 5 star

18 ganesh 04.13.09 at 5:19 am

its very effective

19 Timon 04.14.09 at 7:49 pm

Thank you is very usefull post :)

20 Jordan 05.08.09 at 4:15 am

Thank u very much it works properly

21 Sukhdeep Singh 07.14.09 at 12:51 pm

Thank You
Very very useful post sir

22 anad 07.15.09 at 4:40 pm

worked for me

23 pravin 08.07.09 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 !!!!!!!!!!!!!!

24 Max 08.12.09 at 12:19 pm

very useful info ! Thanks

25 Draco 08.14.09 at 11:11 pm

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

26 Juan Guillermo 08.31.09 at 5:11 am

-r Stands for Recursive and -f Stands for Force

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

27 amit 09.01.09 at 5:39 pm

thanks……….

28 traverlawre 10.19.09 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.

29 Sujan 11.24.09 at 5:08 am

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

30 Shady 12.03.09 at 1:43 pm

excellent article

31 siropio 12.07.09 at 2:28 pm

worked! thanks

32 d134 12.12.09 at 8:45 pm

thanx a lot

33 lalish 02.03.10 at 5:56 am

its niceeeeee

34 Rajive 03.10.10 at 8:01 am

Thanks a lot bro

Helped me a lot.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All