5

I want to find all files in a folder that have -rw-r----- (640? is that the right code?) permissions, and change them all to have -rw-rw-rw- instead. How do I do this, with chmod?

I know I could do the whole folder with

sudo chmod -R 666 /path/to/folder

but I think (perhaps mistakenly?) that it would be more efficient to just do the ones that actually need it?

Alternatively, rather than specifically looking for -rw-r-----, I could chmod any file that doesn't have 666 already? Would that be better?

Braiam
  • 67,791
  • 32
  • 179
  • 269
Max Williams
  • 227
  • 1
  • 3
  • 12
  • You definitely do not want to do chmod -R 666, since it would remove the executable bit from the folder, making it unbrowseable. chmod -R a=rwX maybe. – fkraiem Mar 07 '19 at 10:44
  • 1
    Yes that just occurred to me - I think chmod -R +r,+w might be best. There shouldn't be any executable stuff in that folder anyway. – Max Williams Mar 07 '19 at 10:54
  • If there's nothing executable, including no subfolders, no need for -R, just do chmod 666 /path/*. – fkraiem Mar 07 '19 at 10:58
  • Just to be clear, yes rw-r----- == 640 – wjandrea Mar 07 '19 at 18:57

1 Answers1

16
find /path/to/folder -perm 640 -exec chmod 666 {} \;
muclux
  • 5,154
  • 6
    To find only files (not oddly-specified directories) with permissions 640, add -type f eg: find -type f /path/to/folder -perm 640 -exec chmod 666 {} \; – Pelle Mar 07 '19 at 13:16
  • 5
    And don't forget about using + instead of \; with -exec so it only runs chmod once, instead of separately for each file. – Barmar Mar 07 '19 at 17:13