Chapter 3: Introduction to the Command Line
The command-line, or “terminal”, is a simple text-based interface for providing instructions to your computer. Familiarizing yourself with a few pieces of simple syntax will allow you to efficiently perform a variety of tasks. In this course, we’ll only scratch the surface of using the command-line, as it’s primary purpose is to provide us with an interface for keeping track of our code. In this module, we’ll cover elementary tasks, including navigating a file-system and managing files. Note, some commands may differ for Windows.
Helpful Resources:
3.1 File System Structure
Before exploring the syntax for navigating a file system, it’s important to understand how it’s organized. If you haven’t considered it before, the files on your computer are organized into a hierarchical tree-like structure of folders (directories). Here is an example structure for a Mac machine:
Given this structure, you can go further down a branch, or you can move up a level in the hierarchy. For example, to move from the Mac
directory to the Docs
directory, you would first have to go up to the Volumes
directory, then into the USB
directory, then into the Unix...
directory in order to reach your desired set of files/folders.
3.2 Accessing the Terminal
Opening your command-line will differ based on your operating system, as well as your preferred terminal program (for Windows). On a Windows machine, you should be able to access the Git Bash program from your Start Menu or Desktop icon. On a Mac, the simplest way to open up the terminal is via the Spotlight Search. First, open the Spotlight Search by holding the command
key and hitting the spacebar
. This should bring up the following searchbar:
When the Spotlight Search opens, simply begin typing terminal
, and hit enter
when the terminal
icon appears.
Once you’ve opened the terminal, you’ll have a simple (yet informative) text-based interface that should look like this:
Despite being terse, there’s actually quite a bit of information in this image, including:
- The machine that is being used (this may seem silly, but you can connect to other machines and access their terminals, so this turns out to be rather important)
- The current directory name (though the full path to that directory is not shown)
- The current user, who will have a certain set of priviliages/abilities depending on the configuration of the machine
- A prompt (i.e., the
$
), that indicates that the terminal is ready to accept text instructions
You should now feel comfortable with the idea of how files are organized, and be able to open your command-line. In the following section, we’ll cover some introductory commands that you can begin to use.