How do I delete everything in a directory, including hidden files and directories?
Right now, I use the following:
rm -rf * rm -rf .*
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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.
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.
.* would match