In OS X I am trying to combine the following two commands into a single command in a bash script, so that find
operates once only. The files used by find contain spaces and special characters.
Command 1:
find /path -print0 | tr '\n' '\0' | xargs -0 chmod -N
Command 2:
find /path -print0 | tr '\n' '\0' | xargs -0 xattr -c
Both the above commands work.
I understand from 'Make xargs execute the command once for each line of input' that multiple commands can be executed through xargs
with something like
find /path -print0 | xargs -0 -I '{}' sh -c 'command1 {} ; command2 {}'
However, my attempt to combine the commands with
find /path -print0 | tr '\n' '\0' | xargs -0 -I '{}' sh -c 'chmod -N {} ; xattr -c {}'
results in multiple errors for each file and folder in the /path
, such as
chmod: Failed to clear ACL on file {}: No such file or directory
xattr: No such file: {}
sh: -c: line 0: syntax error near unexpected token `('
Is anyone able to help? Thank you in advance.