My 10 goto terminal commands

4 minute read

There are a lot of useful terminal/shell commands which can make your live a lot easier. I do a lot of backend development, and there is a set of commands which I use a lot during development, testing or operations work. So maybe this list can introduce you to a command that can make your live a little bit easier.

jq

jq is a command which can be used to parse and transform json. I use it a lot in scripts to parse and extract information from APIs, or to quickly format a JSON file. The basic syntax is very easy, but it provides a very large set of operations and command to manipulate the JSON.

JQ for parsing JSON

You can find more information about this tool here: JQ on GitHub

Autojump

A little known command autojump, which keeps tracks of your most used directories, so you can quickly jump between directories. There is a convenience wrapper called j, so I hardly have to use cd to jump between directories anymore, and can just use j instead.

Autojump

You can find more information about this tool here: Autojump on GitHub

Date

Often during work I need to quickly get the current unix epoch timestamp, an ISO formatted date time or quickly determine what time a timestamp actually is. There are a number of websites out there that do this, but I usually just use the specific date commands (and since they are in my history, I usually don’t have to keep the exact parameters in mind). I often use the following:

  • date +%s: Print out the current unix epoch timestamp in seconds
  • date -u +"%Y-%m-%dT%H:%M:%SZ": Print out an iso-8601 timestamp as UTC
  • or date --iso-8601=seconds: Print out an iso-8601 timestamp using local timezone
  • date -d@1550841014: Convert epoch seconds back to a readable date

Date

uuid-Gen

At my last couple of projects we used uuids as unique ids for entities. While this works great, it sometimes gets annoying when writing tests or preparing some data. Luckily we can just use another command line tool to quickly generate uuids.

  • uuidgen: Just creates a uuid with all uppercase characters. Not all tools though work correctly with upper case characters for the UUID strings.
  • uuidgen | tr "[:upper:]" "[:lower:]": Does the same as the previous command, but this time generates them as lower case characters.

Uuid-gen

generate passwords

Another tool which is regularly need, especially when generating users, is a simple password generator. You can use online tools for this, or tools like lastpass. Usually, though, it is quicker to just open a terminal and hit the following command a couple of times: openssl rand -base64 12:

openssl

ncal

Often I need to have quick access to a calendar. Either to plan something, look at what week it is, or just to determine on which day a specific date falls. For an actual agenda, I use google calendar, but I don’t like having to open gmail, or the Mac calendar application, for these simple things. Luckily there are of course CLI apps for that.

ncal

And this is of course a great reason to use lolcat. 😊

hub

Most developers use git to store their data, and often also work with github to store their code. While GitHub works great for most work, and with the normal git command you can do most of the daily jobs, there are some things missing. The biggest thing I miss when working with gitHub, though, is that you can’t simply create or manage PRs from the command line. You have to open the UI, and do it from there. Luckily, though, there is a command called hub which fills in this missing gap.

hub

More information about hub can be found here: https://hub.github.com/

curl

This command is one we’ve already seen in the beginning of this article when we were discussing jq, and one which most people will already know. I still list it, since I use it so often, especially in combination with browsers like Firefox and Chrome allowing you to copy network requests as curl commands, makes this a very useful tool. I often use it together with Insomnia, which I use as a general REST client, and which also allows you to copy specific requests as curl commands.

hub

htop

I develop on a mac, and sometimes need to determine why my system is slowing down to a crawl (answer: usually IntelliJ Idea), or when I’m running a large set of services, I need to monitor what is happening. For this you could use normal top, the Activity Monitor, or just ps, but I often have a simple terminal window open with htop:

hub

vi

You either love or hate vi(m), and I tend to really like it. It’s present on most systems, once you’re used to it, provides a lot of quick commands for editing text files, and is often defined as the standard editor for git. There are thousands of extensions to customize it, use it as a complete IDE, or create an enhanced editor using SpaceVim

vi

cd -, git checkout -

The last command I wanted to show isn’t a real command, but more of a way of navigating directories and branches. I had been doing linux and mac for a couple of years before I learned about this, and it really makes switching directories and switches branches a lot easier and quicker. All you need to remember is that you can quickly switch to the previous directory by just doing cd -, and switching to the previous git branch by doing git checkout -.

cd -

Honorable mention: terminalizer

As an honorable mention I’d like to add terminalizer, with this tool (get it from here), you can very quickly capture a terminals input and output, and generate the Gifs you see in this page. You can even use it to capture terminalizer itself in action.

terminalizer

Updated: