[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bash script problem



> >> find . -type d -exec chmod -v 0644 '{}' \;

> > Use + instead of \; to make them more efficient.

> What does + make as a difference ?

It's a replacement for xargs, except that it actually works, unlike
xargs, which is horribly broken without GNU extensions.

find . -type d -exec chmod 755 {} +

is equivalent to

find . -type d -print0 | xargs -0 chmod 755

except that the former is (a) faster, (b) shorter, and (c) POSIX standard.

Both of them try to minimize the number of separate calls to chmod, by
bundling up a bunch of filenames and passing them all at once.

The \; command calls chmod one time for every directory.

There are valid reasons to use the \; form (e.g. when your command can
only handle one filename at a time), and there are valid reasons to
use the -print0 | xargs -0 form (e.g. when you want to parallelize,
which is another GNU xargs extension).  But in this particular case,
the -exec + command is the best choice.


Reply to: