# How to remove directory with subdirectories and files?

**URL:** <https://community.unix.com/t/how-to-remove-directory-with-subdirectories-and-files/171380>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [May 21, 2007, 4:39am UTC](https://community.unix.com/t/how-to-remove-directory-with-subdirectories-and-files/171380 "2007-05-21T04:39:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ppa108](https://community.unix.com/letter_avatar/ppa108/32/5_5575768a8748004e209b776fc1b2916d.png) [@ppa108](https://community.unix.com/u/ppa108)\
**Post date:** [May 21, 2007, 4:39am UTC](https://community.unix.com/t/how-to-remove-directory-with-subdirectories-and-files/171380/1 "2007-05-21T04:39:53Z")

</div>

I'm trying to remove several directories which contains sun-dirs and files inside.  
I used the command rm -r \<dirname\>  
But, it always ask "examine file in directory \<dirname\> yes/no?" line by line.  
So, i need to write "y" for every line.  
How can i skip this step and remove all directories with asking confirmation?  
Thank you.

---

<div class="post-metadata">

**Author:** ![encrypted](https://community.unix.com/user_avatar/community.unix.com/encrypted/32/114_2.png) [@encrypted](https://community.unix.com/u/encrypted)\
**Post date:** [May 21, 2007, 4:47am UTC](https://community.unix.com/t/how-to-remove-directory-with-subdirectories-and-files/171380/2 "2007-05-21T04:47:27Z")

</div>

\rm -rf \<directory\_name\>

---

<div class="post-metadata">

**Author:** ![the\_learner](https://community.unix.com/letter_avatar/the_learner/32/5_5575768a8748004e209b776fc1b2916d.png) [@the\_learner](https://community.unix.com/u/the_learner)\
**Post date:** [May 21, 2007, 1:52pm UTC](https://community.unix.com/t/how-to-remove-directory-with-subdirectories-and-files/171380/3 "2007-05-21T13:52:16Z")

</div>

I have a similar problem. I have a directory with \*LOTS\* of hidden files (beginning with a . )

In this case when I use rm -rf, I get the error:

rm: Unable to remove directory dir0: File exists

The thing is, I do not know where did all those files come from.. I think I did an nfs mount and something went wrong.. and these random files keep getting produced

-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsD355\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsD455\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsD845\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsD945\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsDA45\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsDB45\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsDC45\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsDD45\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsDE45\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsDF45\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsE055\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsE155\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsE255\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsE355\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsE455\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsE845\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsE945\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsEA45\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsEB45\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsEC45\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsED45\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsEE45\*  
-rwxrwxrwx 1 root engr 8192 May 5 20:35 .nfsEF45\*

even in dir0, rm .nfs\* does not work.

---

<div class="post-metadata">

**Author:** ![ppa108](https://community.unix.com/letter_avatar/ppa108/32/5_5575768a8748004e209b776fc1b2916d.png) [@ppa108](https://community.unix.com/u/ppa108)\
**Post date:** [May 30, 2007, 12:41am UTC](https://community.unix.com/t/how-to-remove-directory-with-subdirectories-and-files/171380/4 "2007-05-30T00:41:06Z")

</div>

I'm sorry to say that the suggestion from "encrypted" really doesn't work.

---

<div class="post-metadata">

**Author:** ![milhan](https://community.unix.com/user_avatar/community.unix.com/milhan/32/80_2.png) [@milhan](https://community.unix.com/u/milhan)\
**Post date:** [May 30, 2007, 7:45pm UTC](https://community.unix.com/t/how-to-remove-directory-with-subdirectories-and-files/171380/5 "2007-05-30T19:45:49Z")

</div>

> [@the\_learner](#):
>
> I have a similar problem. I have a directory with \*LOTS\* of hidden files (beginning with a . )
> 
> In this case when I use rm -rf, I get the error:
> 
> rm: Unable to remove directory dir0: File exists
> 
> even in dir0, rm .nfs\* does not work.

are you sure you have the necessary permissions to operate inside the directory?

typically, rm -rf dir0 should work, even if there are hidden files inside dir0, as long as you have permissions to erase files in the current directory.

---

<div class="post-metadata">

**Author:** ![ppa108](https://community.unix.com/letter_avatar/ppa108/32/5_5575768a8748004e209b776fc1b2916d.png) [@ppa108](https://community.unix.com/u/ppa108)\
**Post date:** [June 12, 2007, 11:52pm UTC](https://community.unix.com/t/how-to-remove-directory-with-subdirectories-and-files/171380/6 "2007-06-12T23:52:19Z")

</div>

I have all necessary permission. But i tried with rm -rf \<dirname\>, i got the following message.

rm: examine files in directory BioDiversity (yes/no)?

How to skip that questions?

---

<div class="post-metadata">

**Author:** ![encrypted](https://community.unix.com/user_avatar/community.unix.com/encrypted/32/114_2.png) [@encrypted](https://community.unix.com/u/encrypted)\
**Post date:** [June 13, 2007, 12:03am UTC](https://community.unix.com/t/how-to-remove-directory-with-subdirectories-and-files/171380/7 "2007-06-13T00:03:47Z")

</div>

As stated previously, use the "\" before rm -rf \<directory\_name\>

---

<div class="post-metadata">

**Author:** ![ppa108](https://community.unix.com/letter_avatar/ppa108/32/5_5575768a8748004e209b776fc1b2916d.png) [@ppa108](https://community.unix.com/u/ppa108)\
**Post date:** [June 13, 2007, 12:12am UTC](https://community.unix.com/t/how-to-remove-directory-with-subdirectories-and-files/171380/8 "2007-06-13T00:12:30Z")

</div>

Yes. It works when i put "\".  
I'm sorry that I did not put "\" before.  
Thanks a lot.

---

<div class="post-metadata">

**Author:** ![prabhukirans](https://community.unix.com/letter_avatar/prabhukirans/32/5_5575768a8748004e209b776fc1b2916d.png) [@prabhukirans](https://community.unix.com/u/prabhukirans)\
**Post date:** [November 24, 2008, 3:14pm UTC](https://community.unix.com/t/how-to-remove-directory-with-subdirectories-and-files/171380/9 "2008-11-24T15:14:09Z")

</div>

Thanks. It worked..)

---

<div class="post-metadata">

**Author:** ![Reboot](https://community.unix.com/user_avatar/community.unix.com/reboot/32/1122_2.png) [@Reboot](https://community.unix.com/u/Reboot)\
**Post date:** [November 25, 2008, 1:02am UTC](https://community.unix.com/t/how-to-remove-directory-with-subdirectories-and-files/171380/10 "2008-11-25T01:02:34Z")

</div>

> [@encrypted](#):
>
> As stated previously, use the "\" before rm -rf \<directory\_name\>

Hi encrypted,

Could you explain the difference between "rm" and "\rm".  
"\rm" command is new to me......

Thanks...
