Email or username:

Password:

Forgot your password?
Darius Kazemi

after 25 years of using the command line... it's probably time I learn how `xargs` works huh

39 comments
[DATA EXPUNGED]
mcc

@darius Can't hurt, but I've "learned" this at least 3 times and it's always easier to write a perl oneliner with `` than it is to figure out which xargs arguments count in the current situation.

Darius Kazemi

@mcc I suppose learning perl would be both easier and more broadly useful than learning xargs

Darius Kazemi

a 2000 word `man` page, a lifetime to master

lime with barcode

@darius sometimes new features come along! I feel like -P was kinda new

Rainbow Stardiver

@darius for all I know, that manual page tells you โ€˜xargsโ€™ is actually short for christargs.

TommyJr

@darius The very existence of this toot suggests you've already ingested the `wc` man page.

Darius Kazemi

@tommyjr `wc` is actually one of a very few commands I can use without checking any documentation!

Steve ๐Ÿ‡จ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ‡ฆ

@darius I learned --no-run-if-empty only Thursday. Truly, I'm not sure if one ever masters xargs. :)

alive

@darius i just pipe things into xargs and pass some random flags that seem nice hope for the best either it'll do exactly what i want or it'll delete everything โ€” an exciting mystery!

Kee Hinckley

@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.

Darius Kazemi

@nazgul good to know that in another 15 years I might at least remember `find` syntax!

Kee Hinckley

@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.

โ›ง esoterik โ›ง

@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.

lime with barcode

@darius @d6 +1, and sometimes I'll just tack on "| tee somefile.sh" and if the output looks good i'll just run it

elle mundy

@darius xargs is the sound i make when i have to use xargs

Nelson Minar ๐Ÿงšโ€โ™‚๏ธ

@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.

Kilian Evang

@darius I use GNU Parallel instead. It can run things in parallel but more fundamentally, it's xargs with a much better CLI.

Bill Hunt

@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: billhunt.dev/blog/2015/05/10/u

Richard

@darius It always takes me more time to figure out how to use it than it saves in processing time. But still worth it just for the joy of seeing parallel stuff happen, and the excitement of wondering if it will complete ok.

Trammell Hudson

@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

Darius Kazemi

@th there are people who are not scared to use spaces in filenames?? news to me, an old

mhoye

@darius @th Macs have never cared. It's kind of embarassing that other operating systems still do tbh.

Naming things might be hard but it sure doesn't help that so many of our tools are trapped in the 70s in so many ways.

OpenComputeDesign

@darius @th I'm not so much "scared" to use spaces, more I find filenames with spaces a major pain, and I hold a small amount of resentment towards anyone who uses them carelessly.

Anthony Sorace

@darius I hate it. Half of the common usage feels like compensating for shells with bad quoting rules or subprocess capabilities.

botvolution

@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

yr

@darius xargs is simpler than it appears, and incredibly useful. i recommend also checking out gnu parallel

Eli the Bearded

@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
find dir ars -print0 | xargs -0 prog {} # tedious so much typing
find dir args -exec prog {} + # nice, no xargs needed

for thing in $(find dir args) ; do
# handy loop, but $IFS sensitive
done

Glyph

@darius if you need xargs you should *probably* be using a general purpose programming language

EMi

@darius Meanwhile, I will NOT learn how it works but I will pronounce it in a very silly way out loud while my puppy gives me a weird look

Tom Carchrae

@darius first step is pronouncing it... which should be done with a heavy pirate accent

Go Up