Skip to content

Instantly share code, notes, and snippets.

@acidtone
Last active September 6, 2023 22:22
Show Gist options
  • Save acidtone/316d2bd9cf59f841684dbd68ffc3ee95 to your computer and use it in GitHub Desktop.
Save acidtone/316d2bd9cf59f841684dbd68ffc3ee95 to your computer and use it in GitHub Desktop.
Command Line Basics

Command Line Basics

Navigating the file system

Most of the command line tools you use as a developer (like Git, Node and npm) will assume that you are in the root directory (i.e. top folder) of your project. We will cover the three system commands that help up us navigate the file system.

Notice: The examples below start with a $. DO NOT include this when typing commands; it's there to represent the command prompt.


pwd - Present working directory

Use the pwd command to see where you are when you open the terminal.

$ pwd

The starting directory for most systems will be your home directory.

/Users/YOUR-ACCOUNT-NAME

Your goal is to navigate to the root of your project. For example:

/Users/YOUR-ACCOUNT-NAME/Documents/projects/portfolio

ls - List directory contents

List the contents of your current directory with the ls command:

$ ls

The -l flag lists extra information about the contents:

$ ls -l

Add the -a to list hidden files:

$ ls -a

You can also combine multiple options with a single flag. To list extra information and also all hidden files:

$ ls -la

cd - Change directory

Use the cd command to switch to another directory. Assuming you are currently in your home folder, you can move to your downloads folder with:

$ cd Downloads

OR, move there from anywhere on the system with an absolute path (replace username with your login handle):

$ cd /Users/username/Downloads

Move up one directory:

$ cd ..

OR move up many directories

$ cd ../../..

Move multiple directories "downstream":

$ cd some/path/relative/to/your/location

Combine ../ with a relative path for more flexibility. To move to a directory that adjacent to your _present working directory`:

$ cd ../adjacent-directory-name

If you get lost you can always move to your home directory:

$ cd

Quality of Life Tips

  • The tab key auto-completes file names and directories.
  • Use the Up Arrow to browse through the history of last used commands.
    • Pro tip: type your command first and the Up Arrow will filter the history!

Related things

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment