Ubuntu – Permisions set to unknown after chmod 777

chmodpermissions

I just noticed that after running

chmod 777 * 

on a directory that has sub-directories in it does what you would expect. It sets the permissions of everything, including the sub-directories to 777. However, if you then decided that you didn't want to do that, and run

chmod 644 *

Now the contents of the sub-directories get set unknown permissions and you cannot change them back.

Why does that happen? Is this the expected behavior, or a bug? Is there a way to restore the file permissions?

Since the files I had were in a zip file in another location, I just deleted the entire directory, and unzipped the zip file again, but I would like to know the causes of this "problem", and it's remedies.

Some additional info, I am running those command on a remote machine over SSH.

Best Answer

Probably best to use find for this sort of thing.

Directories need to be x access , files do not, so different set of permissions.

# Files
find . -type f -exec chmod 644 '{}' \;

# Directories
find . -type d -exec chmod 755 '{}' \;
Related Question