Apart From Blonde

View Original

Series Week 5 - Basic Terminal Commands

Hi everyone!! Thanks for coming back for another week of the Talk Like A Developer series. This week I’ll introduce you to the basic terminal commands used at any level (no coding required!).


About this series: This series isn’t going to give you everything you need to roll up your sleeves and start coding. What it will do is give everyone, even the people who have no idea what computer science is, the ability to talk and ask questions about these topics so that if you are interested in getting into the hands-on/technical side of these topics, you’ll know where to start, what to Google, and how to ask for help!


If you haven’t already, check out last week’s post: Week 4 - Frontend VS Backend Development as well as Key Coding Terminology For Beginners to get up to speed on the common terminology used in this series!


If you already know what a terminal is/how to open it and want to jump straight to learning the commands, skip ahead to the “Let’s Get To The Commands” section below.

What is the terminal:

The terminal isn’t a place where you write code. It’s a place you run simple commands (usually related to code you wrote somewhere else). A “command” is exactly how it sounds - you’re telling the computer to do something!

Terminal commands are usually short 1-line statements that you execute by hitting Enter. On the outside, while they’re super short, some of these commands look like confusing combinations of random letters and characters. However, if you know what you want the computer to do, it’s actually pretty easy to find the command you need on Google. I promise you, even after 5 years of coding, I still Google things like “terminal command to do X.”

Why does the terminal matter:

Using the terminal is a pretty unavoidable activity when working with any level of coding. Luckily, it can be easy to learn and there are only a handful of things you really need to know (the main one is knowing what questions to Google). Developers mainly use the terminal to run and test their code, and while the terminal commands involved in doing those are easy to learn, that will be a topic for another time.

What I will show you in this post:

This post will walk you through the most basic terminal commands which allow you to “explore” your computer from your terminal. Just like you can click on folders on your computer to navigate to inner folders or files, you can use the terminal to navigate in and out of those same folders. Don’t worry - these have nothing to do with writing or testing code - you don’t even need to open any other application. These commands are crucial to know as they’re used almost daily by developers at every level.

How to open the terminal app:

Every computer has a built-in terminal, so you won’t need to download anything to access it. The app looks like this on a Mac:

For anyone else on a Mac, don’t search “Terminal” in finder - you’ll get hundreds of unhelpful results. Instead, click on the Launchpad icon in the row of apps at the bottom of your screen and search for “Terminal” from the search bar at the top. After clicking on the app, this is what a terminal window looks like from a Mac:

All that random info just tells you “where you are” on your computer (in my case I’m in my account on my mom’s computer). The little grey box next to “%” indicates where anything I type will show up.

Let’s Get To The Commands:

Throughout this post I reference an example I’ll call “Folders XYZ”. All you need to know for now is that on my computer’s desktop there’s a folder called Folder_X which contains a folder called Folder_Y. Inside that folder is another folder called Folder_Z. Folder_Z is empty. Here is a visual representation:

Other thing to know: When it comes to terminal command terminology, a “Folder” on your computer is called a “Directory”.


Here are the commands you’ll learn and what they mean:

Ls (list out the contents of the current directory)

cd folderName (change directory into folder named folderName if it exists)

cd .. (move one level higher from the current directory)

mkdir folderName (make a directory named folderName if it doesn’t already exist in the current directory)

rmdir folderName (remove the directory named folderName if it exists)

Don’t worry if this doesn’t make sense yet - it will once you start doing it yourself, and I highly recommend following along in your own terminal!

Once you open your terminal, type Ls and hit Enter. As I mentioned, you’re simply asking your terminal to list the contents of the directory you’re currently in. By default, you’ll always be on the “highest level” of items on your computer right when you open the terminal app.

In the Folders XYZ example, Folder_X is the highest/most-outward level of the 3, so you have to move inwards/lower to get to Folder_Y’s level and even one level lower to get to Folder_Z. So the default directory when you open your terminal is so “high” that you can’t move up/out any levels - you can only move inwards/down.

Here is what I see when I type Ls:

These are the directories on the highest level of my computer. Ls doesn’t actually do anything other than give you information. I usually use this to know where I am and what my options are for where I can move next. Let’s say I want to see what’s on my desktop. I would type cd desktop (as I mentioned, this means change directory to desktop) and hit Enter.

NOTE: Terminals Can Be Case-Sensitive!: On a Mac, I can use “cd desktop” or “cd Desktop” and they’ll both work, while on another computer, I might be required to use “cd Desktop” since that’s how it’s listed. Similarly, some of the commands are case-sensitive: you can type “ls” or “Ls” and both will work on a Mac, yet “cd” works while “Cd” doesn’t. You can always try upper and lower case on your computer for any command to see what works if you’re unsure.

Moving Into Folders:

I’ve now navigated to my desktop. In order to actually see what’s on my desktop, I need to type Ls and then Enter again. If I wanted to move farther in, would just type cd and the folder name and hit Enter again, and so on.

Rules for moving between folders:

  • You can only change directories into folders (you can’t go “inside” a file)

  • You can only move into a folder that’s on the next level from your current one. If you’re unsure which folders are on the next level, the “Ls” command gives you that info.

    • In case that was confusing, see the example below:

Back to Folders XYZ, if I’m in Folder_X, I can’t go straight to Folder_Z. I have to move into Folder_Y first and then I can move into Folder_Z. In this image I used my terminal to demonstrate this case:

This is important because when developers want to run/test code in a given file, they can’t simply run the necessary command from any directory. They first have to use the terminal to navigate to whatever folder contains the file they are trying to run.


Moving Out of Folders:

You’ll simply type “cd ..” and hit Enter:

Here is a visual that demonstrates moving between folders in the XYZ example:

Making a New Folder:

Type “mkdir folderName” (which means make directory and name it folderName). You can name it anything you want as long as a folder doesn’t already exist with that name in your current directory.

Removing a Folder:

Type “rmdir folderName” (which means remove the directory that’s called folderName). Assuming that folder exists in that directory level, it will delete that folder. Back to Folders XYZ - if you’re inside Folder_X, you can’t say “rmdir Folder_Z” because Folder_Z isn’t on your current directory level. You’d have to do “cd Folder_Y” and then “rmdir Folder_Z” for it to work. Here I’ll demonstrate that case as well as remove the directory I created above called “Folder_A”:

There are some ways to spice up these commands or use combinations of these commands to make shortcuts, but this covers an introduction to the basics! If you have any questions about these or ran into any issues with your terminal, please let me know in the comments below or email me at techblog@apartfromblonde.com! I’d really love to help!!


Thank you so much for reading and come back soon for another Talk Like A Developer post!

Check out this and more posts on my Medium account HERE!