after 25 years of using the command line... it's probably time I learn how `xargs` works huh
after 25 years of using the command line... it's probably time I learn how `xargs` works huh 39 comments
[DATA EXPUNGED]
@mcc I suppose learning perl would be both easier and more broadly useful than learning xargs @darius for all I know, that manual page tells you โxargsโ is actually short for christargs. @tommyjr `wc` is actually one of a very few commands I can use without checking any documentation! @darius I learned --no-run-if-empty only Thursday. Truly, I'm not sure if one ever masters xargs. :) @darius Iโm at 40+ years of not using xargs. I think last month was only the second time where I decided it was worth figuring out (and then forgetting) the options. โfindโ and that weird โ{} \;โ, otoh, is embedded in my fingers. @nazgul good to know that in another 15 years I might at least remember `find` syntax! @darius Iโm pretty much limited to the -exec command -- I just imprinted on it at an early age. That weird -mtime -atime stuff where you canโt actually enter the comparison date, you have to create a file to compare it too.... That commandโs showing itโs age. @darius my tip is to use `xargs echo cmd` instead of `xargs cmd` so you can play around and see what would happen. less intimidating if you aren't worried about fucking up. @darius the -0 flag is a real lifesaver (combined with find -print0). GNU parallel has been a useful tool for me in the past, too. @darius I use GNU Parallel instead. It can run things in parallel but more fundamentally, it's xargs with a much better CLI. @darius I cover it briefly in my article on unix tools, I mainly use it when I need to pass arguments around to multiple calls but am too lazy to write a full shell script for capturing output: https://billhunt.dev/blog/2015/05/10/unix-tools/ @darius I'm "scared to use spaces in filenames" old, so I recommend always "find -print0 | xargs -0" just in case there are any surprises @th there are people who are not scared to use spaces in filenames?? news to me, an old @darius I saw this on lobste.rs a while ago https://www.oilshell.org/blog/2021/08/xargs.html @darius I hate it. Half of the common usage feels like compensating for shells with bad quoting rules or subprocess capabilities. @darius I literally only finally learned last year, and I won't say it changed my life, and I still don't understand -0 but it's one of those niche things that is occasionally just a neat, elegant solution to a niggly cli problem @darius I find I rarely need it. Between shell looping and non-dumb use of find, not much need. find dir args -exec prog {} \; # dumb one at a time for thing in $(find dir args) ; do @darius first step is pronouncing it... which should be done with a heavy pirate accent |