3 ms·
We're losing the art of bash ``` find -type f -iname '*.go' | xargs -r -n1 sed -i 's,foo,foobar,g' ```
by sigmonsays 2y ago
We're losing the art of bash
```
find -type f -iname '*.go' | xargs -r -n1 sed -i 's,foo,foobar,g'
```
- mh- 2y agoSomething that frequently trips me up, mostly when helping colleagues, is the arguments to both find and xargs differ substantially between GNU and the FreeBSD-derived ones that ship on macOS.
- asicsp 2y agoWhy 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.
- theamk 2y agoxargs 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)
- asicsp 2y ago`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.
- lofaszvanitt 2y agoThe problem is... if you use these on rare occasions it gets frustrating, because you have to read the manual or google everything or ask the llm again and again. noone can remember these abbreviations
- KetoManx64 2y agohttps://atuin.sh/ https://atuin.sh/ is such a huge productivity booster in these scenarios. I remember that I used find + xargs command sometime in the last 6 months on of my computers and with Atuin I can quickly find it and then slightly modify it to fit my current need.
- fwip 2y agoYou can save useful snippets in a file for later use.
- feelamee 2y agoyes, but... noone except your shell! Fish is perfect and very very often can guess what I want using pwd, file existence, current prompt, etc...
- IshKebab 2y agoYeah it's great! Difficult to remember Bash pipelines are being replaced with modern tools with good UX.
- sigmonsays 2y agoI disagree, They are not difficult to remember. you'll never build good UX and a powerful tool. You're either a master of your tool or you're not.