Getting started with terminal - Try replacing utility services with CLI

By: Kannan Ramamoorthy On: Thu 10 January 2019
In: Command-Line
Tags: #Command-Line #Productivity

Intro:

In my opinion, using terminal makes you more productive and lets you get your mundane tasks done quickly. For ex, I spend no more than few seconds for the tasks like,

  • Encoding/Decoding a string to and from base64.

  • Formatting/Validating a JSON.

  • Formatting/Validating an XML.

  • Searching files containing a particular string.

  • Find and replace a particular pattern.

  • Sort/de-duplicate a text content.

  • And similar tasks that I do regularly.

But it was a bit difficult for me to convey these things to the people around me and pass on the comfort that I have so that they will also get more productive on similar tasks.

This is an effort to try to convience someone to start using CLI.

Step-by-step:

Typically, the general alternatives for the tasks mentioned above are some websites that offer encoding, decoding, formatting, and validation. The steps to achieve what they intended to do is,

  • Copy the text that they need to encode/decode/validate/format.

  • Paste it to the site that performs expected action.

  • Click on encode/decode/validate/format.

  • Copy the output.

  • Paste it back to the intended place.

Example:

I believe these are fair enough use-cases that let you start with command-line. I am trying to compare the step-by-step breakdown of CLI and non-CLI way of achieving a base64 encoding.

Without using CLI,

  • Copy the string that needs to be encoded.

  • Open some website like www.base64encode.org and paste your string there.

  • Click on encode.

  • Copy the output text.

  • Paste it in your intended location.

While doing the same thing with CLI,

  • Copy the string that needs to be encoded.

  • In terminal execute the command pbpaste|base64|pbcopy.

  • Paste the base64 encoded string to the intended location.

Note: pbpaste pastes the content from the clipboard, pbcopy copies the content to the clipboard. If you are a non-mac user, try finding the equivalent of it.

Benchmarking:

As verified, I took 28.62s in the way of not using CLI and took 17.50s when I executed in CLI.

To be fair, I assumed that I already have knowledge of the site and the knowledge of the commands and typed in those by hand.

The time taken when you using non-cli is nearly 63% more than the time it was taken in CLI. Further, you can save more time if you have the CLI version defined as an alias.

Summary:

  • Apart from the time that you save, CLI’s are more native to your system that provides you more power which is not available otherwise. For ex, you can format the content of a json file and save it to another file using the one-liner, cat "ip_file" | jq . > "op_file". In a non-cli way, you will be required to take care of file operations(reading/saving the file) yourself manually.

  • You will also be able to combine multiple commands to achieve something new, that might not be possible when you are using separate services for each use cases. I’ll try to prove more on that in the upcoming articles.

  • Once you start using the terminal, you understand that commands provide so many options that it is difficult to have a UI with all possible functionalities that a terminal can provide.

In general, I strongly believe that commands let you do more without spending much time in fiddling on different services. Compiled some of my commonly used commands here, might be helpful for you if you have already faced the use-cases mentioned there.


If you found the article helpful, please share or cite the article, and spread the word:


For any feedback or corrections, please write in to: kannangce@rediffmail.com

comments powered by Disqus