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?


2 Answers 2


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.

  • Perfect, many thanks for this!
    – Sam
    Commented Mar 2, 2020 at 13:45
  • 3
    +1 for including the echo and instructions on its use for a dry run. Commented Mar 2, 2020 at 23:08

If it is a git repository's worktree, just checking out the files should fix their permissions. I.e., do a git checkout -f.

  • Thanks for this and it's actually kind of what I did (I just moved my local files and re-cloned from the remote) but it felt like a bit of a cheat (it didn't really teach me anything) so I wanted to ask the question anyway so I know for future. Hopefully Google indexes this nicely and then it's a handy reference in future.
    – Sam
    Commented Mar 4, 2020 at 8:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .