Will rm -rf * remove all files/folders in the current directory

globbingshell

Will rm -rf * remove all files/folders in the current directory ? I want to make sure the wildcard * won't move up in upper directories and erase all my filesystem. 😀

I remember doing chmod 777 .* -R to chmod hidden files and it chmoded all my filesystem. Obviously, I was on the root account.

Best Answer

No, if you did not tweak your shell a lot this will not remove files or directories starting with a .. To remove them, too, you can either list them explicitly

rm -rf .file .dir

or use the right glob patterns (thanks Chris)

rm -rf .[^.]* ..?*

EDIT The point here is that you cannot use .* to match files like .file, because .* or .*? will also match .. or .. .[^.]* matches files like .file, while ..?* matches files like ..foo (* matches zero or more characters while ? matches exactly one).