3

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?

1

2 Answers 2

11

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.

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

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

1
  • 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
    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 .