Terminals & The Shell: A Quick Primer

What’s a Terminal, You Ask?

Picture this: Imagine you walk into an office and you see a desk with a telephone on it. You pick up that phone to talk to someone in another department.

A terminal is a bit like that phone — it’s the piece of equipment that lets you start a conversation. It’s a way of “talking” to your computer.

It’s where you’ll type SSH to hop into your cloud server and command it to do your bidding.

Simply put, it’s your control center – and where you will be spending most of your time telling your computer what to do.


Let’s do a brief history lesson.

Imagine the Stone Age of computing — monstrous computers, punch cards, and enough cables to double as a jungle gym. Back then, the terminal was a physical device — a keyboard and a screen wired directly to a computer. Picture retro green text on a black screen and the unmistakable sound of keyboards clattering. These were the OG interfaces between man and machine.

Terminal.jpg
An operator using an old IBM 3270 Terminal, circa 1980

Fast forward to now, and our ’terminals’ are software emulations of those vintage behemoths. They still serve the same purpose: just like that office phone connects you to other departments, today’s software-based terminals are your direct line to “talk” with your computer.


Every Operating System comes with a default terminal, but there are other (snazzier) options as well.

 Windows:

  • Windows Terminal: This one is a jack-of-all-trades – customize it, tab it, split it. Perfect for the user who wants to dabble in both PowerShell and CMD.
  • PowerShell: For those who like to wield some real power and automate everything.
  • Git Bash: It’s bash. It’s for Windows. Need I say more? It’s particularly useful if you’re working with Git repositories.

 MacOS:

  • Terminal: Ah, the built-in option. It’s the vanilla ice cream of MacOS terminals. Classic, yet dependable.
  • iTerm2: For those who want to go beyond vanilla and into the realm of mint chocolate chip with hot fudge. It’s feature-rich and integrates well with Zsh.
  • Wezterm: My personal favorite. Endlessly customizable, but may be a bit advanced to start with initially.

 Linux:

  • Gnome Terminal: When you want something as reliable as your mom’s spaghetti recipe. It’s the default for many GNOME-based distributions.
  • Konsole: For those KDE purists out there. It’s snappy and integrates seamlessly with your KDE Plasma environment.
  • Terminator: When you want to feel like you’re on a futuristic cyborg mission. Ideal for those who love splitting their terminal windows into a bajillion panes.

There are a ton available, each with their strengths and weaknesses. A more comprehensive list can be found on this Github page.


large_shell.jpeg
No, not this kind of shell.

Now, back to the phone analogy – let’s say you pick up the phone and you start talking. The person on the other end understands English, so you give them instructions in English.

That person who understands you and does what you ask is like the “Shell” in a computer.

A “Shell” is a type of software that understands the commands you type into a terminal and translates them into actions that the computer’s operating system can understand. So, it acts like an intermediary between you and the computer’s operating system. When you type a command like ls -l ./My_Folder it’s a way of telling the computer “show me the list of files in My_Folder”. The shell figures out what that means and tells the operating system to do it.

Now, remember the tidbit about the person on the other end of the phone speaking English? There are different kinds shells, each with their own ’language’ (otherwise known as syntax). For example, Bash (Born Again Shell) is popular on Linux and macOS, while PowerShell is the popular go-to for Windows aficionados. Depending on your shell, you may have to type slightly different commands, but with any shell you can script complex tasks, automate your life, and generally make your computer sing, dance, and juggle flaming chainsaws.

Bash (Bourne Again Shell):

Birthed as a successor to the Bourne Shell (sh) in the late ’80s, Bash has since become the de facto shell on Linux and macOS.

Features

  • Scripting Capabilities: Excellent for automating tasks or running programs.
  • Extensibility: Numerous built-in commands and the ability to use external commands.
  • POSIX Compliant: Adheres to the Portable Operating System Interface standard, making it widely portable.
  • Sample Command:
    • ls -la lists all the files in a directory, along with details.

Best For: Linux and macOS users, developers who need a reliable and well-documented shell.

PowerShell:

Introduced in 2006 to replace Windows’ Command Prompt, it’s a task automation and configuration management framework.

Features

  • Object-Oriented: Manipulates objects rather than text, providing more control.
  • .NET Integration: A smooth marriage with Windows’ .NET framework.
  • Scripting: Uses its scripting language, PowerShell Script (PS Script), for automation.
  • Sample Command:
    • Get-ChildItem does the same thing as ls in Bash.
      • Note: PowerShell is, for the most part, a bit more verbose than Bash.

Best For: Windows system administrators, users looking for a powerful and flexible shell, .NET developers.

ZSH (Z Shell):

Features

  • Autocompletion: ZSH anticipates your needs like a butler for your keyboard.
  • Themes and Plugins: Customizable to the max with the oh-my-zsh framework.
  • Scripting: Inherits Bash’s capabilities but adds its own sugar.
  • Sample Command:
    • ls *(.om[1,3]) lists the three most recently modified regular files.

Best For: Users who want Bash’s power but with a custom flair.

Fish (Friendly Interactive Shell):

Features

  • Syntax Highlighting: Yes, like in an IDE.
  • Autosuggestions: Fish suggests commands as you type, based on history and completions.
  • Web-based Config: Customize your fish in a GUI environment if you wish.
  • Sample Command:
    • ls *.txt shows real-time highlighting.

Best For: Those who want a friendly and colorful experience out of the box.

Others to Consider:
  • Csh (C Shell): Syntax is akin to the C programming language. Used mostly on BSD systems.
  • Ksh (KornShell): A Unix shell that combines features of other shells. Good for scripting and interactive use.
  • Dash (Debian Almquist Shell): Lightweight and fast, generally used for running system scripts.

Hopefully you’ve picked out a Terminal, now it’s time to learn how to ‘speak’ with the shell.

Heads Up
For now we’ll be focusing mainly on Bash as it’s the most common shell on server-based systems, but I’ll do a deep dive into PowerShell and ZSH in a followup post.

Let’s get our feet wet with some simple but incredibly useful Bash commands:

Navigating Directories

  • ls: List all the files and folders in your current directory.
  • cd [folder-name]: Change your working directory.
  • pwd: Print the name of the current directory you’re in.

Example:

ls
cd Documents
pwd

File Operations

  • touch [file-name]: Create a new empty file.
  • rm [file-name]: Delete a file.
  • cp [file-name] [destination]: Copy a file to another location.
  • mv [file-name] [destination]: Move a file to another location.

Example:

touch newfile.txt
cp newfile.txt anotherfile.txt
rm newfile.txt

Reading and Writing Files

  • echo [text]: Print text to the terminal.
  • cat [file-name]: Display the content of a file.
  • nano [file-name]: Open a file in a simple text editor called Nano.
  • vi [file-name] Open a file in Vim

Example:

echo "Hello, World!"
cat anotherfile.txt
nano anotherfile.txt
vi anotherfile.txt

System Information

  • uname: Show the operating system name.
  • df: Display disk usage information.
  • top: Display a dynamic view of system processes.

Example:

uname
df
top

That’s it for our quick primer on terminals and the shell! Just a quick recap, we’ve covered:

  • What a terminal is
  • What the shell is
  • How they work together to allow you to interact with your computer (or server)
  • A few basic Bash commands to navigate around in the shell comfortably

But hold tight; this is just the tip of the iceberg. In our next post, we’ll dive deeper into the shell, exploring more advanced topics like:

  • File permissions
  • Environment variables
  • Basic scripting

Cheers!