In this series you will learn basics of using the terminal with bash. By the end of this you will know:

  • The differences between a bash, a shell, a console, a terminal, and the command line.
  • The basic commands to traverse your computer from the terminal and how to customize your terminal
  • The structure of commands, arguments, and options in bash
  • How to edit, move, create, and delete files from the terminal
  • How to discover new commands and inspiration for more

Prerequisites:

  • None

What is a Command-Line Interface/CLI?

Like with most acronyms its often easiest to understand each word first. For CLIs the first word is Command-line. This refers to your terminal emulator (or just termial for short), more specifically the command you enter into your terminal (for more details click the words below).

Console

A console is a physical terminal, which you probably have never seen before. You might hear it in code/tech circles, but almost always they are refering to the terminal/terminal emulator.

Terminal

A Terminal Emulator or terminal for short emulates a console so that you can interface with the computer with the command-line. Modern terminals have a plethora of upgrades compared to days past such as customization history settings, mouse features, etc.

Command-line

The command-line is the area to the right of your command-prompt (by default its $). This is where you actually enter the command that you wish to be executed by the terminal.

Shell

The shell is the command-line interpreter, in other words its the language you use on the command-line. The most common example of course is bash, but zsh is super popular since it is now the default for MacOS and many Linux Distros.


And of course the I stands for interface, or just a way for someone to interact with an app/program. So putting it all together a CLI is simply just a way of interacting with different programs or apps from the terminal as opposed to having to open up the GUI (or graphical user interface: the normal way to interact with an app which typically allows you to click buttons to use it).

CLIs have a ton of benefits, first they are significantly faster. Many programs, especially the big ones take a long time to even start up/open the GUI. If you learn to effectively use CLIs, you can often complete the task from the terminal before you would have even been able to open the app. Second, in many cases CLIs are much more powerful then using a GUI because you have access to all the apps functionality, where GUIs need to have made/implemented that button for the feature to be accessed. So if you learn to use the command-line, you might gain additional functionality for your apps that you were not able to do via the GUI.

Finally, and perhaps most importantly, CLIs allow you program your interactions with an application. By programmatically scripting your actions, you automate the whole process. So, let’s imagine you had 50 images that you need to change the name of for an experiment (or just to be more organized). To do this via the GUI you would need to open Finder or Windows Explorer, right click, then click rename, then change the name of that individual image, then rinse and repeat. Even for people who know all the keyboard shortcuts (btw they are enter for MacOS and F2 for Windows), this would take a long time. But with a CLI you can do the whole thing with a few lines of code. This might look scary at first, but over the course of this series you will know exactly what code like this means (btw this will rename a bunch of images for you).

i=1
for filename in *.jpg; do
  new_name = "img_$i.jpg"
  echo "Change $filname to $new_name"
  mv filname $new_name;
  i=$((i + 1))
done

Of course this is not an isolated use case, you might need to convert word documents to PDFs or create an entire folder struture for a new project; heck, I even use CLIs to check everytime I update my CV/Resume to autmatically update my website with the changes and automatically link to any new publications or presentations. Some other super cool use cases for CLIs that I use include watching Anime from the terminal with a CLI and downloading all the apps I used, install all the fonts, and change all my settings to my prefered options on a new computer. Once you have the ability to programmatically control these actions, the world is your osyter, and you are only limited by your imagination.

If you are not convinced that CLIs are amazing, then I am not sure what else I can say. But I am sure most of you are intrigues at this point. So over the course of this series, I will start you off on how to use CLIs. You will learn how to used the basic commands and how to put them together into a script to run at your own leasure without having to type them all out each time. This tutorial will get you started on your path with bash. By the end you will know all the basics, so you can easily navigate a terminal only system like a Super Computer or Cloud server. So, before you start, check out the section below, which shows you how to get the terminal running on your OS.