4 ms·
I think that you probably have 80% of the gross capability, but you will gain a huge level of refinement. I'm about 10-15 years into the command line (depending
by amalgamated_inc 4y ago
I think that you probably have 80% of the gross capability, but you will gain a huge level of refinement. I'm about 10-15 years into the command line (depending on how you count, lol) and I keep finding more stuff that just wouldn't stick 5 years ago, because I simply didn't have those problems yet.
E.g. there was a time in my life when I didn't get what `xargs` even did, I literally couldn't grok it. Now, I can't imagine life without `-0`!
The composability of UNIX commands is just so amazing. Every command builds on every other command. I haven't seen that with any other tools or program.
- tester457 4y agoWhat is the most helpful thing you do with xargs and -0?
- dredmorbius 4y agoEasily handling arguments with whitespace is the obvious answer. e.g.: find . -type f -print | xargs wc -l vs. find . -type f -print0 | xargs -0 wc -l If you have filenames with whitespace, the first will skip a bunch of files. If you're doing processing on other inputs which may include whitespace, you'll be able to handle those using xargs without worrying about additional delimiting. And for those not aware, '-print0 / -0' arguments to find(1) and xargs(1) respectively tells the first to output ASCII NUL delimited arguments, and for the latter to expect the same. As ASCII NUL should not normally occur within any argument, it's the ultimate delimiter. I've used xargs and/or bash loops to do some fairly heavy-duty web scraping given an input list of arguments. Using xargs allows multiple simultaneous parallel queries such that any one request stalling out doesn't hold up all process.
- dredmorbius 4y agoAnd to clarify, by "skip a bunch of files", what I of course mean is that if your document is named "Your Document.md", what the first find(1) command will do is attempt to run "wc -l" on "Your" and "Document.md", neither of which it can find, a fact about which it will complain bitterly, creating much noise in your shell session. It will fail to run "wc -l" on the file "Your Document.md", which the second example will do correctly (and not on the name-fragments). "wc -l" gives a line count for a file. That's ... not especially advanced, but is a trivial example of an xargs command which you should be able to try without causing any problems on your own system.