Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm sorry for asking such a basic question:

How do I delete everything in a directory, including hidden files and directories?

Right now, I use the following:

rm -rf *
rm -rf .*
share|improve this question
You can combine them to rm -rf .* *. – user unknown Mar 21 '11 at 3:38
You can go one directory up and then run rm -rf yourdirectory/* – shreyansp Apr 5 at 9:08
sorry missed the hidden directory part. The previous users solution covers that – shreyansp Apr 5 at 9:15

The best answer is: Don't do that. Recursively remove the directory itself, then recreate it as an empty directory. It's more reliable and easier for other people to understand what you're trying to do. When you re-create the directory it may have a different owner, group and permissions. If those are important be careful. Also, if any running programs have open file handles (descriptors) on the directory then you won't want to remove it. If none of those special cases apply, then it's simpler to remove the entire directory.

share|improve this answer
So how is that more easy. 'Be careful' isn't an answer. I wouldn't understand why somebody deletes a directory and rebuilds it again. – user unknown Mar 21 '11 at 3:36
I added the phrase "as an empty directory", perhaps that's more clear. – Chris Quenelle Jul 2 '13 at 22:49
No, it doesn't explain why you delete a directory and recreate it then. To the things to consider belongs, btw., date/time of creation too. – user unknown Jul 2 '13 at 23:14
If that directory is the current working directory of some process, you may run into problems. Also, if you remove the directory, you remove information about its permissions and ownership. – Evan Teitelman Jul 3 '13 at 0:03

Simple and straight forward:

find -delete 

Includes directories and hidden files. At least gnu-find knows -delete, your find may differ.

share|improve this answer
rm -rf -- * .[!.]* ..?*

Each of the three pattern expands to itself if it matches nothing, but that's not a problem here since we want to match everything and rm -f ignored nonexistent arguments.

Note that .* would match ...

share|improve this answer

Assuming bash 4+:

shopt -s dotglob
rm -rf -- *
rm -rf ./*

With dotglob enabled, * expands to all files and directories, even those that begin with . - but doesn't expand to . and .., so it is safe to use with rm.

share|improve this answer

if you are in the directory:

cd .. && rm -rf dir && mkdir dir && cd dir


rm -rf /path/to/dir && mkdir /path/to/dir

share|improve this answer

Oh my Zsh

rm -rf (.|)*

Again, this is for Zsh only.

share|improve this answer
Or *(D) (the D glob qualifier turns on the glob_dots option for this pattern). – Gilles Jan 28 '11 at 20:14

How about using find. I think this is generally a good choice, when you have to dig through sub-directories.

find . -type f -exec rm {} \;
share|improve this answer
there is a -delete switch, so you can delete directories. (at least in gnu-find). – user unknown Mar 21 '11 at 3:40

Try rm -rf *?*. This will delete normal and hidden files.

share|improve this answer
Not in any shell that I know of. – Gilles Jan 27 '11 at 22:45
you are correct. it does not deletes sub-directories. – gladimdim Jan 28 '11 at 18:03
The problem is more likely to be that *?* will not match “dot” files/dirs (unless you have enabled the dotglob option in bash, the GLOB_DOTS option in zsh, or an equivalent for whatever shell you are using). – Chris Johnsen Jan 29 '11 at 3:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.