Linux – chmod all files (including hidden files) in a directory in Linux (not recursively)

chmodfileslinux

Yesterday I did something stupid which I today realised. I ran:

/root# chmod o-rwx * .*

This supposed to remove read, write and execute permissions for the world on all files in the current directory (/root). As soon as I did this, screen behaved weird, I couldn't run commands as a non-root user, and ssh refused to work unless I logged in with root.

This was caused by the fact that bash expanded .* to .. too! Now, how do I chmod all files in a directory with chmod, without using find, a loop or another language like perl?

Best Answer

If you're using bash then setting dotglob will make * also match files that begin with a ..

shopt -s dotglob
echo *