An introduction to Mac’s Terminal (Part I): CLI vs GUI

JuxtaposedWords
3 min readFeb 14, 2016

--

An introduction to Mac’s Terminal

It is important to note this article is intended for the most novice terminal user. This is NOT for those who want to patch over their Homebrew installation.

Dexter Douglas. Neo Anderson. Ender Wiggin. What do they have in common? They used the terminal to change their world. Let’s talk about how we can use the terminal to change your world.

The average user typically uses the Graphical User Interface(GUI). The GUIs were invented in the 1960’s. Unsurprisingly the GUI created a low barrier to entry for computers. Windows, Mac, and even Ubuntu Desktop use a GUI for interacting with the operating system. Before the GUI paradigm there was the command line interface(CLI).

GUIs are regarded by many as what made computing so accessible to people. The intuitive nature of visual interactions creates an incredibly low barrier to entry for users, but at the same time the GUI limits the abilities of users. While the Command Line interface has a larger barrier to entry, it offers much greater rewards.

Most every machine still ships with a command line interface of one form or another, but sadly the Command Line is often shrouded in arcane mystique (if you are in doubt, please watch CSI or Swordfish). Both systems, GUI and CLI, provide ways to interact with the operating system. Each interface has their own benefits and drawbacks.

What is Terminal?

Earlier we established that the command-line interface was an alternative way to interact with the operating system. The terminal is simply an application that allows us to interact with a shell. “Simply put, the shell is a program that takes your commands from the keyboard and gives them to the operating system to perform.[1]

Understanding What we See

A breakdown:

DemoMachine     - the name of the computer I'm using
~ - the current directory(see note below)
juxtaposedwords - the user I’m logged in as
$ - tells us where the cli prompt starts
A note on "~" - the tilde is commonly used to represent the current user’s home directory

Getting started

If you’ve used the mac for any amount of time you’ve become familiar with “Finder,” that program you use to search through folders. We’ll use that familiarity as the basis for our first example.

Type the following code into the terminal, each line followed by an enter:

DemoMachine:~ juxtaposedwords$ cd ~
DemoMachine:~ juxtaposedwords$ pwd
DemoMachine:~ juxtaposedwords$ open ~
DemoMachine:~ juxtaposedwords$ ls

So our output should look something like:

Each CLI command has several factors when it is being run:

  • Current User — who is running the command
  • Current Working Directory — where is the command being run from?

While a GUI clearly has a current user (who you are logged in as), the current working directory is best seen when we use finder. We’re always at a specific folder before moving on.

Now let’s talk about what those commands mean:

“cd ~” : Change the working directory to ~, a shortcut for the home directory of the current user

DemoMachine:~ juxtaposedwords$ cd ~

“pwd” : Tells us where we are in the file-system

DemoMachine:~ juxtaposedwords$ pwd

“open ~” : open the directory “~”, the current user’s directory, with finder.

DemoMachine:~ juxtaposedwords$ open ~

“ls”: list the contents of the current directory

DemoMachine:~ juxtaposedwords$ ls

Important Shell Concepts:

  • Just like with most GUIs, you are always logged in as a user
  • You always perform commands from a particular place (the “working directory”)

In this example, we saw how the “ls” command just shows us what is in the directory we provide. Now you may have noticed a pattern. Commands typically follow the pattern of “command [target]”.

The next post will cover some more basic terminal commands and ideas of the terminal.

Next: Part II: Flags

--

--