16

I noticed:

chmod -R a+x adds execute permissions to all files, not just those who are currently executable.

Is there a way to add execute permissions only to those files who already have an execute set for the user permission?

Clinton
  • 22,361
  • 15
  • 67
  • 163

2 Answers2

27

Use find:

find . -perm /u+x -execdir chmod a+x {} \;
Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
  • 5
    Use `-execdir`; it's safer than `-exec`. Also since `chmod` accepts multiple files in one command line, `+` instead of `\;` may have better performance. – jw013 Aug 04 '11 at 07:57
  • thanks for mentioning the `+` mode! The `-execdir` instead of `-exec` squashes the gained performance benefit again, though; and since find delivers full file paths anyway, does it matter much? the fastest command for me was `... -exec chmod {} +` – codeling Dec 30 '13 at 12:43
5

You can use find to get all those files:

find . -type f -perm -o+rx -print0 | xargs -0 chmod a+x

Update: add -print0 to preserve space in filenames

Reto Aebersold
  • 16,306
  • 5
  • 55
  • 74
  • 3
    Don't do it that way, it screws up with spaces in the filenames. If you want to pipe to xargs, use the `-print0` find option and the `-0` xargs option. – Mat Aug 04 '11 at 07:55