Introduction to the Command Line
Written by Kashif Nazir, updated by MichaelThis course will not focus on using the command line, but a few core concepts and skills will be helpful If you are already familiar with the command line (e.g. from CS107), you can skip this page.
Concepts
- The command line is just another way of controlling your computer.
- It is a textual interface. The icons that you commonly interact with (i.e. click on) are parts of a graphical user interface. They can accomplish many of the same things!
- For most development work, a CLI (command line interface) is much more expedient because it allows you to work more fluidly with code and run code/commands that do not have a graphical user interface. At the command line, you are navigating the same file system and computer that you would in Finder or a file explorer.
- However, you have way more control over what you can see and do. This is really powerful, but with great power comes great responsibility. Command line interfaces are often designed with the assumption that their users are comfortable with the command and know exactly what they want. This means, for example, that many commands (like deleting file) will not warn you, nor provide a way to undo (such as moving files to Trash). Please be particularly careful when copying commands you find online.
Accessing the command line
Depending on your operating system, you will have a different application to use the command line interface through:
- macOS: Terminal
- Windows: Windows Terminal (or Windows PowerShell)
- Windows 11 introduced Windows Terminal, which is, as far as we can tell, just a nicer UI around PowerShell.
- By installing Git through the instructions in the setup page, you will be able to install common Unix commands like those listed in this tutorial to be used in PowerShell.
- Windows PowerShell also has all the commands you need built-in, but some are different from the Unix-like ones, and the outputs are often formatted differently. If the commands mentioned don't work, try looking up the PowerShell equivalent.
- Linux: Varies by desktop environment. You probably know where it is because you probably needed it to install and configure Linux...
Command Line Guide
Check out CS107's resources page for video- and text-based guides to many commands and concepts.
In particular, we recommend checking out the following topics:
- Unix Filesystem Overview
- The Working Directory and pwd
- Absolute and Relative Paths
- Changing Directories with cd
- Listing A Folder's Contents with ls
Note: The guides reference and show examples involving the afs directory. This directory is a shared filesystem on the Stanford cluster machines. You won't have this directory on your computer. From your home directory (the directory the terminal starts in), you should see folders for your Desktop, Documents, etc., so you will be able to access any files you download or create outside of terminal through those folders.