←back to thread

131 points tomschafer | 1 comments | | HN request time: 0s | source
Show context
sigmonsays ◴[] No.42151991[source]
We're losing the art of bash ``` find -type f -iname '*.go' | xargs -r -n1 sed -i 's,foo,foobar,g' ```
replies(4): >>42153830 #>>42153991 #>>42154761 #>>42155854 #
asicsp ◴[] No.42153991[source]
Why use `xargs` instead of `-exec`? And if you do need `xargs` (for example, for parallel processing with `-P`), it is recommended to use `-print0` with `find` and `-0` with `xargs` to avoid issues due to filenames.
replies(1): >>42154608 #
theamk ◴[] No.42154608[source]
xargs passes many inputs to one script invocation, so even with a single thread there is often a dramatic speedup.

(and agree re -print0/-0, it's absolutely essential)

replies(1): >>42155707 #
1. asicsp ◴[] No.42155707[source]
`find` can do that as well with `{} +` (at least, the `GNU` implementation and it'll automatically add more invocations if there are just way too many files).

In any case, OP was using `-n1` which means one file per invocation.