Day 29: Conquering My Fear of xargs & curl

I am preparing myself to add new programs to my terminal and I’m a little intimidated to be honest. I thought I should cover a few core commands before I try to add some more. Thankfully, after I watched a few videos on xargs and curl I feel a lot better about taking the next step.

TLDR;

Okay, so here are the highlights of what I did:

  • I watched a few videos on the xargs program and the curl program. I wrote some notes on both of them. The curl program had a ton of options but the common options were what I practiced with.
  • I reviewed how to use the sed command and practiced running some substitutions to convert command options into an HTML table format. It’s not easy though lol.

xargs Notes

xargs is a command-line program that reads streams of data from standard input and then generates and executes commands with that read data. Basically, xargs takes standard input from one program and allows us to pass that input as an argument in another program/command.

Although many command-line programs can accept standard input, there are still many that cannot. For example the echols, and rm programs cannot accept standard input. See the example below and try to notice the difference.

# This command fails to show any output because echo cannot read the input being piped to it by the ls programs output.
ls -al | echo

# This command now works because xargs handles the input and passes it along to echo in a format that echo can read.
ls -al | xargs echo

There are multiple of programs where xargs works great with. One in particular, is the find program. Although find has the -exec flag that allows it to pass it’s output as an argument to another program, xargs can do it faster and with more features that can manipulate the data stream to better match the requires of the program that will utilize the data next.

Conclusion

That’s all for today. If you are interested in the MIT course you can check out the video lecture I’m currently going through. The lecture is helpful but isn’t sufficient by itself. Anyways, until next time PEACE!

YouTube player