Cheat-Sheet: Command-Line Interface

Joe C Gomez
4 min readMar 22, 2021

Have you ever noticed in movies or TV shows that when the “awesome computer hacker person” needs to do something really important, you see them typing a lot of text on a screen and violà something seemingly magical happens?

It seems very intimidating and makes you think the movie “The Matrix” is a real thing when seeing it in action. But in reality this way of working with the computer is called the Command-Line Interface, CLI, and you don’t have to be a hacker to learn and use the CLI

In fact you used something similar without you even knowing. The “Finder” on Mac, “File Explorer” on Windows, or “Commander” on Linux are the prettier version of CLI. All of these programs are known as Graphical User Interface, GUI, and it functions the same way as the CLI but with prettier graphics.

As you can see, we have “Application”, “Desktop”, “Documents”, “Downloads” in our Terminal and Finder. We just have access to do more in our Terminal!

Us developers use the terminal/command prompt to enter these command lines. Whether it be navigating from point A to point B, creating directories, and deploying programs. All of these commands are simply to execute and I’m going to walk you through them!

First, let’s open our Terminal/Command Prompt.

Mac: cmd + spacebar (Then type "Terminal")Windows: windows key (Then type "Command Prompt")Linux: Ctrl + Alt + T

Commands

  1. pwd
  • First, let’s type “pwd” (“print working directory”) and hit enter. This command tells you which path you’re in. It’s like looking at a street sign, because sometimes you get lost!
  • When opening our Terminal, it automatically puts you in your home directory. As you can see, the path “/Users/joegomez” is my home directory.

2. ls

  • Stands for “list”. After you run it, you should then see a list of all the directories/files within your working directory. Since we’re in our home directory, we see all the other directories that are inside.
  • Adding an “-a” flag means “all information” including hidden files

3. cd <Name of Directory>

  • This is the most import command to know, it stands for "change directory" and it has many functions. This command lets us navigate up and down our computer, we can think of it as a tree. The home directory is the trunk, our directories inside of it is are branches, and our files are the twigs.
  • We are currently in our home directory but let’s move down into our Document directory with “cd” and see what’s inside of it with “ls”.

TIP: Hit “tab” key to autofill!

4. cd ..

  • To move up, we can simply add 2 dots at the end of cd

5. cd

  • If you down many directories and want to return back to your home directory, then we can simply enter cd
  • So instead of entering many “cd ..”s to return back to our home from our current path (/Users/joegomez/Documents/Flatiron/mod4/React-Pizza-Scott/src/components) we simply enter cd

6. open

  • As you can guess, this opens a file or directory

7. mkdir <Name of Directory(ies)>

  • This command let’s us add a new directory in the current path that we are in

8. rm <Name of File(s)>

  • Stands for “remove”, this command only works for files and not directories!

NOTE: When you delete a file it’s permanent, there’s no going back!

9. rmdir <Name of Directory(ies)>

  • This command removes directories and like rm, it’s permanent.

10. mv <Name of File(s)>

  • This command let’s us “move” files between different directories
  • I’m going to move a file named “joe” from the “hello” directory to the “world” directory
  • “~/” let’s us return back to our home directory!

Now you show off your new skills to your family and friends, and feel like a hacker now! These are the basic commands, but of course there’s advanced commands that lets you do more than move couples files around.

More CLI Commands: https://www.w3schools.com/whatis/whatis_cli.asp

Even though the CLI is super useful/powerful tool it is easier to run dangerous commands through the CLI than through a GUI. So do some reading on different commands!

--

--

Joe C Gomez

Find some time to do something! 🧠 Flatiron Alumni 🏛