This is a post from Danny Levy, a writer, a friend, and a former colleague from my time at DigitalOcean. Danny doesn’t have an engineering background but has worked for years at getting more technical.
We’ve all seen it before, the ominous black screen where engineers pitter-patter unintelligible alpha numeric globs of code like witches brewing a stew of newt’s tails and toad’s eyes. For business people who have bravely taken steps towards becoming more technical, we might find ourselves face to face with these dreadful black screens where a giant leap of faith or a supernatural event must take place to help us do something with it. We may be afraid, but it behooves us to understand it.
The CLI, or Command Line Interface, is simply a place to write commands that your computer follows, and that can make you a lot more productive. You can use the CLI to perform a wide range of tasks, such as managing files and folders, installing software, running scripts, and communicating with other computers on a network, and, yes, even writing code.
🚨 Confusion Alert 🚨
CLI technically refers to anything that you interact with in the Terminal. You’ll hear developers refer to the Terminal as the CLI, but you also may see software that you use may offer a CLI. What that means is just that they have an interface you can use in the Terminal to run specific commands and do things with it, like Heroku’s.
🚨 Confusion Alert 🚨
But what is a CLI/Terminal? What am I actually using? The command line interface (CLI) or terminal is a way to interact with a computer system using text-based commands, which means instead of clicking buttons, menus, and windows on a graphical user interface (GUI) with your mouse to perform commands, you’re actually writing the command in for your computer to follow. You can think of the terminal as a way to bypass Finder (or whatever if you’re on a PC), and issue commands directly to your computer, like Finder is doing behind the scenes.
You can ask any engineer, and they will tell you (with a straight face) there are many benefits to using the command-line interface, such as increased efficiency and the ability to perform tasks quickly and programmatically. With a few keystrokes, you can accomplish a task that might take multiple mouse clicks and menu selections in a GUI. And it’s not just that – much of the work engineers do in the terminal isn’t even possible in a GUI.
So what tasks are these engineers completing? Why are they important? And to put it so eloquently, what the hell are they doing in there? Generally, you can break it down into a few categories:
Running scripts and files – engineering workflows live in the terminal. A developer might need to run a script to install dependencies for an app, clean up their local cache, you name it.
Viewing scripts and files – this is especially common for logs, or records of what happened on a particular server.
Interacting with the cloud – provisioning infrastructure, logging into a remote server to see what’s going on, etc.
Handling version control – creating new branches, seeing who messed up that build that was working an hour ago, etc.
Using other CLIs – most developer tools (like Heroku) provide some sort of interface to use it via the command line.
There are a million things developers use the command line for! It’s arguably the most important – and most common – tool in the whole engineering world.
Well, let’s take some time and try to get familiar with what’s going on. Let’s take our laptops and open the terminal, and try out some basic commands to get an idea of how we can use them in specific scenarios, such as file management (moving, editing, deleting, copying our files) and searching for specific data within files within our laptop. And once we take those digestible first steps to get familiarized, the terminal might seem a bit less intimidating.
Take a deep breath. Ok, let’s go.
On our Mac, let’s open up “Terminal,” Apple’s own CLI. In the top right corner of your laptop, there is a magnifying glass icon:
Click on that, type in “terminal,” and click on it, and a black screen will appear. Congrats, this is your terminal. When you’re typing in your terminal, you’re communicating almost directly with your computer’s operating system, without the “translation” layer that is Finder. It’s like talking to your boss’s boss. Or something like that.
The first thing you will see on your black screen is the date of your last login:
You’ll see some added details followed by a white box, this is where you will be writing your commands:
A “shell” is how you talk to your operating system without having to write code that looks like ones and zeros. There are a bunch of different shells out there, but a popular one for Macs is zsh, which is what you’re seeing above.
Let’s go ahead and type in our first command:
ls or “list” is a command that lists the files and directories in the current working directory. What you’re doing is simply looking at the contents of a folder in a file explorer:
When you opened your terminal, it defaulted to plopping you in your computer’s “root” directory, or in other words the highest possible file level. In that folder, or directory, are familiar faces like Desktop, Downloads, and the whole lot.
Did your head explode? I hope not, but let’s continue down this journey. Perhaps we want to find out what music we have on our laptops. Since we can’t dust off that old Creedence album or remember who last borrowed that Snoop Dog bootleg that isn’t on any of the streamers, or an old brilliant song you recorded, we’ll have to find it on our laptop, remember, we’re not going to open Apple Music or Spotify (the GUI!) because that would be too hard. We’ll go ahead to do it the easy way. Look, we’re changing the way we think about CLI already!
Ok, for our next command, let’s type in:
find music - just like that. Guess what this command does? That’s right, it lists all the music files everywhere and anywhere on your laptop. Don’t be overwhelmed, as you’ll see a plethora of files that will come up Matrix-style, everything from Garage Band recordings to iTunes songs.
To find a particular song, press Command+F and type in the name of the song you’re looking for. Terminal will quickly highlight that song and file for you! I actually found an old song I thought I lost while writing this!
Now that we’ve done two massive commands in our CLI let’s pat ourselves on the back. But before we continue, let’s do one more command. Since our screens are filled up with all this coding jargon, let’s type in the command:
Now that we’ve cleared our screens and our minds, let’s try to navigate directories on our Mac. Let’s now type
cd followed by a space and the name of a directory to where we want to navigate. This command changes the current working directory in the CLI. Think of it as opening a folder in a file explorer. “cd” just stands for “change directory” by the way.
Let’s now navigate to the "Documents" directory. In order to do that, let’s type
cd documents and press Enter.
We’re now in the Documents folder! Now, let’s type
ls (remember this?) to list the contents of the directory you are currently in. All of your documents will show up in a list.
We did it! We did a simple exercise using the
cd command to navigate between directories and used the
ls command to list our contents in our Terminal. Though this may seem pretty basic, the workflow of
ls → cd is actually something that developers do every day.
A lot of what developers do in the terminal is run files. When you’re writing code, a particular file might have an output, and you need to run it to get that output. In our directory here, we’ve got a file called
scrape.py that scrapes the web for something useful. We can run that file with
python scrape.py and see the output right in the terminal:
You can do a lot more than just look around. You can remove a file with
rm, create a file with
touch, create a folder with
mkdir, and even (accidentally, of course) delete all files on your Mac and destroy it with
rm -rf. To be clear, do not run this, or you will be doomed. When it comes down to it, most of what developers are doing in their terminals all day is just running files and looking around things. It’s as simple as that.
So let’s pause here and review what we’ve done. We’ve looked into our laptop’s files, we found our old recordings and bootlegs we thought were lost. We’ve run a file that scrapes the web. So when you have your next sync, you can damn well tell your team, especially the engineers on your team (!), that you’ve been playing ‘round in the CLI and that it was ‘fun.’
After all, this is our first dive into the black screen of death. Did we die? No. Did the sky come crashing down? Certainly not. What we’re doing is familiarizing ourselves with a very intimidating tool that initially scares off ~99% of non-engineer technology professionals. But it didn’t scare us off, we’re exposing ourselves to it. We’re taking it slow and going through these steps little by little, shwaya-shwaya.
Have you tried using the terminal yourself? How have you found it useful for your day-to-day? Let me know in the comments.
Editor’s Note: I told Danny that nobody would understand what this means. Look it up I guess.
The CLI is an incredibly powerful tool for developers and for anyone wanting to process some data. Using just a few simple commands, like: sort, wc, uniq, grep, cut you can build quite complex data processing and analysis of text files.