Get to Know Your Terminal
Every operating system comes with a text-based command line interface (CLI) for issuing commands. This provides a powerful way to accomplish things that the graphical user interface (GUI) may not expose.
Already know your way around a terminal? Skip ahead to setup!
# Find your OS terminal
- On macOS, the default console is Terminal (opens new window).
- On Windows, the default console is called Command Prompt (opens new window).
- On Ubuntu Linux, the default console is called Terminal (opens new window).
There are other apps like Hyper (opens new window) (cross-platform) and iTerm2 (opens new window) (Mac), but your system’s terminal will work fine! Most mobile operating systems (Android, iOS) do not expose a console application, for security reasons.
For a more in-depth introduction to your computer’s command line, the Ubuntu guide (opens new window) (also linked above) is a great resource.
# Run a command
Once you’ve launched your terminal, you’ll be greeted by an empty prompt.
A command is simply a piece of text that is interpreted and executed by the system. Commands often include the names of programs, references to files and folders, flags, and other arguments. Throughout the tutorial, we’ll ask you to “run” commands—that just means you’ll type the text into your terminal and press Return or Enter. If a number of commands should be run in series, they may appear in a single snippet.
The terminal is extremely powerful. Only run commands from sources you trust!
If you are inclined to copy-and-paste commands into your terminal, keep an eye on your selection—it’s easy to inadvertently copy extra characters that can confuse the terminal.
Let’s run your first command. Type
whoami into your terminal, and press Enter:
whoami # -> oli
You should see your username printed to the terminal!
The line beginning with a
# is just an example of the expected output. Unless your name is Oli, you’ll probably see something else!
# Navigate directories
We’ll eventually want to run commands alongside your site’s code, so you’ll need to know how to move around your computer’s filesystem.
Commands are run in the “working directory.” To find out what your working directory is, run…
Some commands will differ between platforms. Whenever they do, the code snippet will include tabs, like the one above.
Do you recognize the name of the folder? Let’s check its contents, just to be sure:
You should see a list of files and folders. Most terminal applications launch with your “home” folder as the working directory.
Some terminals display the current folder in the text of the prompt. On macOS and Linux, your home folder is usually displayed as a tilde (
~), so it may not be obvious.
You can change the working directory with the
cd command, followed by a relative or absolute path. Try out a few of these:
cd .. pwd cd /Applications pwd cd ~/Desktop pwd cd ~ pwd
On most systems, pressing the Up arrow will show you previously-run commands. Pressing Up multiple times goes farther into your history. At any point, you can press Enter to execute the command, or the Left and Right arrows to modify the command.
This series of commands is a common pattern when navigating your filesystem is to:
- Figure out where you are with
- List files with
- Navigate to a new folder with
When changing folders with
cd, you often only need to type the first couple of characters in a directory name, then press Tab to autocomplete it. The terminal will only autocomplete up to a point that there is ambiguity. For example, in a directory with folders named
practice, you could type
cd pro and press Tab to autocomplete up to
cd project-—then just type the last character for the directory you want.
Now that we’ve poked around a bit, it’s time to pick a place to stash your project.