Linux – Recursive chmod to 644 Where Current Permission is 755

chmodlinuxpermissions

I copied a project directory to a portable hard disk, wiped my laptop and copied the project back, but now git reports loads of changes due to files that previously had 644 permission changing to 755.

I could recursively chmod all files and directories to 644, but then I get a load more changes in git (so looks like not everything was 644 previously). Is there any way to chmod only files that have 755 permissions?

Best Answer

The documentation for find (see man find) writes,

-perm mode File's permission bits are exactly mode (octal or symbolic). [...] See the EXAMPLES section for some illustrative examples.

So you can match files and change their permissions like this

find path/to/files -type f -perm 0755 -exec echo chmod 0644 {} +

Remove the echo when you are comfortable that it's showing you what you expect, and run it again.

Related Question