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?

  • 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 7 '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 7 '19 at 10:54
  • If there's nothing executable, including no subfolders, no need for -R, just do chmod 666 /path/*. – fkraiem Mar 7 '19 at 10:58
  • Just to be clear, yes rw-r----- == 640 – wjandrea Mar 7 '19 at 18:57
find /path/to/folder -perm 640 -exec chmod 666 {} \;
  • 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 7 '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 7 '19 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.