4 ms·
xargs is also more efficient than -exec, as it stuffs multiple files to the target command. Esp. for rm, instead of executing a copy for each file.
by derekp7 7y ago
xargs is also more efficient than -exec, as it stuffs multiple files to the target command. Esp. for rm, instead of executing a copy for each file.
- detaro 7y agodoesn't -exec <command> {} \+ do that too? (and we're back at the "remembering specific syntax" point: knowing xargs helps you everywhere)
- Izkata 7y agoBoth of these are valid: -exec <command> <args> {} + -exec <command> <args> {} <args> \; (The backslash is unnecessary for +) The first one, the one used here, acts like xargs. The second one executes <command> individually for each file found. Because the "+" version continually adds files to it, it must be last, but the "\;" version doesn't have that restriction since it's a single substitution. Just to be clear with an example: $ ls one three two $ find . -exec echo 11 {} 22 \; 11 . 22 11 ./two 22 11 ./three 22 11 ./one 22 $ find . -exec echo 11 {} 22 + find: missing argument to `-exec' $ find . -exec echo 11 {} + 11 . ./two ./three ./one Most people seem to only learn one of them, even getting them mixed up. For example, I had learned the "\;" one and for years thought they both acted like that, with "+" simply being an alternate end-of-command identifier to avoid needing to escape the semicolon.
- Xophmeister 7y agoThe “+” terminator to -exec has the same effect for find.