4 ms·
There's numerous examples of useful long commands, here is one: perl -p -i -e 's#foo#bar#g' **/*
by silverwind 1y ago
There's numerous examples of useful long commands, here is one:
perl -p -i -e 's#foo#bar#g' **/*
- PaulDavisThe1st 1y agono limits: find . -type f -exec perl -p -i -e 's#foo#bar#g' {} \;
- Someone 1y agoThat runs perl multiple times, possibly/likely often in calls that effectively are no-ops. To optimize the number of invocations of perl, you can/should use xargs (with -0)
- dr4g0n 1y agoNo need for `xargs` in this case, `find` has been able to take care of this for quite some time now, using `+` instead of `;`: find . -type f -exec perl -p -i -e 's#foo#bar#g' {} +
- tremon 1y agoxargs constructs a command line from the find results, so if **/* exceeds the max command line length, so will xargs.
- Someone 1y agoxargs was written to avoid that problem, so no, it won’t. https://man7.org/linux/man-pages/man1/xargs.1.html https://man7.org/linux/man-pages/man1/xargs.1.html: “The command line for command is built up until it reaches a system-defined limit (unless the -n and -L options are used). The specified command will be invoked as many times as necessary to use up the list of input items. In general, there will be many fewer invocations of command than there were items in the input. This will normally have significant performance benefits.” Your only risk is that it won’t handle inputs that, on its own, are too long.