What is the command line?
When you use a computer, you probably click on icons, drag windows around, and open apps from a menu. That style of computing is called a Graphical User Interface, or GUI. Each graphic is a "window" where you can see the contents of the computer without typing anything.
But before the GUI existed, there was the Command Line Interface, or CLI. In a CLI, everything is text. You type a command, press Enter, and the computer types an answer back. No icons, no windows, and you don't need the mouse at all!
- You click icons and menus
- Easy to learn, great for everyday use
- What most people use today
- You type text commands
- Fast and powerful once you know it
- Used by pros like network administrators
Even though most people prefer a GUI, the CLI is still everywhere. Many Linux systems run on it, and advanced users rely on it to manage computer networks and systems. With the CLI you can access, change, and move files without clicking a single icon. The app where you type these commands is usually called a terminal.
Precision matters: when typing CLI commands, capitalization and spacing are important. To the terminal, Documents and documents are two different names!
Reading the prompt
When you open a terminal, the first thing you see is the prompt. It looks cryptic, but it's actually a status report. It tells you who you are, what computer you're on, and where you're standing in the file system, then it waits for your command.
That squiggly character ~ (called a tilde) is a shortcut that means your home folder, the folder where your personal stuff lives. As you move into other folders, the prompt updates to show your new location, like student@codehs:~/Documents$.
Getting around: pwd, ls, and cd
Your computer's files are organized like a tree of folders inside folders (in CLI-speak, folders are called directories). Imagine your home folder looks like this:
├── Documents/
│ └── homework.txt
├── Photos/
└── notes.txt
Three commands are all you need to explore this tree:
- pwd stands for print working directory. It prints the full path of the folder you're standing in, in case you get lost.
- ls stands for list. It shows everything inside your current folder.
- cd stands for change directory. cd Documents steps into the Documents folder, and cd .. steps back up to the folder above you. The two dots always mean "the parent folder."
# Where am I? What's here? Let's explore. pwd ls cd Documents pwd cd .. pwd
/home/student Documents Photos notes.txt /home/student/Documents /home/student
Pro move: typing cd all by itself (or cd ~) teleports you straight back to your home folder from anywhere. Great for when you're lost!
File paths: absolute vs. relative
A path is the address of a file or folder. There are two ways to write one:
- An absolute path starts from the very top of the file system (the / "root") and spells out the whole address: /home/student/Documents/homework.txt. It works no matter where you're standing, like a full mailing address.
- A relative path gives directions from where you are right now: if you're standing in your home folder, Documents/homework.txt is enough. It's like saying "two doors down."
The ~ shortcut you met in the prompt works in paths too: ~/Photos means "the Photos folder inside my home folder," no matter where you currently are.
Good to know: Linux and macOS terminals separate folders with forward slashes (/). The Windows Command Prompt uses backslashes (\) and some different command names, but the ideas are exactly the same.
Making and managing files
Navigating is nice, but the real power is doing things to your files without touching an icon:
- mkdir games makes a directory (a new folder) called games.
- touch list.txt creates a new, empty file called list.txt.
- cat notes.txt prints a file's contents onto the screen so you can read it.
- cp list.txt copy.txt copies a file (the original stays put).
- mv list.txt Documents/ moves a file somewhere else. It's also how you rename: mv old.txt new.txt.
- rm copy.txt removes (deletes) a file.
Careful with rm! The command line trusts you completely. rm does not send files to the Trash or ask "are you sure?" The file is gone, instantly and permanently. Always double-check what you typed before pressing Enter.
Try it: your own terminal
Time to be a command line detective. Below is a simulated terminal with a small file system inside it. Complete these missions using only typed commands (stuck? reveal a hint):
1Look around
Figure out where you are, then list everything in your home folder.
2Read the secret note
There's a file called notes.txt in your home folder. Print its contents to the screen.
3Build a games folder
Make a folder called games, go into it, create a file called highscores.txt, then come back home.
4Clean up carefully
Go into Documents, check what's there, and delete homework.txt. (Don't worry, it's the simulator's homework, not yours.)
Click the terminal and type a command, then press Enter. Type help to see everything it understands, and clear to wipe the screen. Press the up arrow to repeat a command.
Command reference
Keep this table handy. These are the Linux/macOS commands; Windows has its own versions (like dir instead of ls, and del instead of rm), but they work the same way.
| Command | What it does | Example |
|---|---|---|
| pwd | Prints the path of the folder you're in ("print working directory") | pwd |
| ls | Lists the files and folders in the current folder | ls |
| cd | Changes into another folder; cd .. goes up one level | cd Documents |
| mkdir | Makes a new folder | mkdir games |
| touch | Creates a new empty file | touch notes.txt |
| cat | Prints a file's contents on the screen | cat notes.txt |
| cp | Copies a file to a new name or place | cp a.txt b.txt |
| mv | Moves or renames a file | mv a.txt Photos/ |
| rm | Deletes a file. Permanent, no Trash! | rm b.txt |
| whoami | Prints the username you're logged in as | whoami |
| ps | Shows the programs (processes) currently running | ps |
| top | Live view of running programs and how much power they use | top |
Peeking at the system
Not every command is about files and folders. Some tell you about the computer itself:
- whoami prints which user account you're using, which is handy on shared computers.
- ps lists the processes (running programs) on the computer. If an app is frozen or unresponsive, ps helps you find it, and you can even close it right from the terminal.
- top is like a live scoreboard of processes, showing which ones are using the most of the computer's memory and power.
This is why network administrators and cybersecurity professionals love the CLI: they can check on dozens of machines, spot a misbehaving program, and fix it, all with a few keystrokes.
whoami ps
student PID TTY TIME CMD 1042 pts/0 00:00:00 bash 1187 pts/0 00:00:02 python3 1201 pts/0 00:00:00 ps
Decoder ring: in that ps output, each row is one running program, and the PID (process ID) is its unique number. Telling the computer to stop process 1187 would close that Python program.
Common CLI commands
The command line is a text-based way to talk to your computer. This bash script shows a few commands you might use every day.
Quick quiz
1. You're lost somewhere deep in the file system. Which command prints exactly where you are?
2. You're in /home/student/Documents and want to go up to /home/student. What do you type?
3. Why should you be extra careful with the rm command?
Keep exploring cybersecurity
You can now navigate a computer without touching the mouse. Next, use those command line skills to manage networks, or dig into digital evidence like a real investigator.