Super User is a question and answer site for computer enthusiasts and power users. 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

rm -rf * will remove all files and folders but not hidden ones.

rm -rf .* will remove all hidden files and folders, but not those that are not hidden, correct?

What command should one type, in order to delete all files and folders including the hidden ones? (except . and ..); ?

share|improve this question
up vote 10 down vote accepted
rm -rf * .*

will do the trick.

share|improve this answer
Yes. :) Thanks a lot. – MEM May 19 '12 at 15:39
NO! .* will expand to all invisible entries in the current directory including .. -- which means that using .* as an argument to rm -rf will attempt to delete the directory above the one you're currently in, and all of its contents. rm will refuse to do it, but I don't consider relying on this safe... – Gordon Davisson May 19 '12 at 15:54
@Gordon Davisson: I've created a directory. I've added files to it, including hidden files. I've make that command. It has deleted all the contents inside that directory recursively, and it haven't deleted any content ABOVE that directory. Can you please clarify your comment ? – MEM May 19 '12 at 15:58
Thanks for the clarification on your comment above. Now I understand your point. Any alternative suggestion then ? – MEM May 19 '12 at 16:01
@GordonDavisson rm should print a rm: "." and ".." may not be removed message in that case – it'll not automatically remove the parent directory. – slhck May 20 '12 at 13:57

Try this:

find . -mindepth 1 -delete

I'm not certain that -mindepth is supported by all implementations of find; if yours doesn't have it, -path should give another way to keep it from trying to delete .:

find . -path "*/*" -delete
share|improve this answer
BSD find has that option too, yup. – slhck May 20 '12 at 13:58

Just use this command to purge files/directories according to specific criteria:

# tmpwatch -fauv 0 .
share|improve this answer

shopt -s dotglob also makes * include files that start with a period.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .