0

I have this:

 chmod u+x $(find scripts -name "*.sh")

But I believe it's only running chmod u+x for the first item in the list from find, since the results are newline separated.

How can I run chmod u+x for each item returned from the find call?

My guess is that xargs is the best way? something like this:

 find scripts -name "*.sh" | xargs chmod u+x
Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

1 Answers1

2

The safest way to do this is to let find execute chmod directly, and also to be more careful in the selection of the files:

find scripts -type f -name '*.sh' -exec chmod u+x {} +

This will find all regular files in or below the scripts directory that have names that end with .sh and will run chmod u+x on as many of these as possible at once. It will handle possibly weird filenames without issues.

To change the permissions on only those files that needs it:

find scripts -type f -name '*.sh' ! -perm -u+x -exec chmod u+x {} +
Kusalananda
  • 333,661