---
title: Terminal 101
description: Terminal Commands Cheat Sheet: pwd, cd, ls, grep, find, man, etc.
tokens: ~825
---

# Terminal 101

## `man` - the manual for any command

```bash
# Syntax: man [command], for example:
man pwd                                 # manual for pwd command
```

## Navigating

```bash
pwd                                     # print working directory (current directory)

cd [folder]                             # change directory
cd ~                                    # go to home directory
cd ..                                   # go up one directory
cd ~/[folder]                           # cd via home-relative path
cd -                                    # go to the directory you last browsed to

ls                                      # list directory contents
ls -a                                   # list all, including hidden files
ls -l                                   # list in long format

open [path]                             # open a file or folder

```

## File management

```bash
mkdir [folder]                          # create a new directory
mkdir -p [folder]/[subfolder]           # create nested directories
mkdir [folder] [folder] [folder]        # create multiple directories
rmdir [folder]                          # remove a directory

touch [file]                            # create a new file
vi [file]                               # create or edit a file in vi editor
nano [file]                             # create or edit a file in nano editor

cp [source] [destination]               # copy a file
cp -r [source-dir] [destination]        # copy a directory recursively
mv [source] [destination]               # move or rename a file or directory

rm [file]                               # remove a file
rm -r [folder]                          # remove a directory
rm -rf [folder]                         # remove a directory and all its contents
```

## Viewing

```bash
cat [file]                              # show the contents of a file
less [file]                             # scroll through a file, without flooding the terminal
head -n [number] [file]                 # show the first [number] lines of a file
tail -n [number] [file]                 # show the last [number] lines of a file
```

## Search (grep and find)

```bash
find [directory] -type f -name "[file]"      # find a file in a directory
find [directory] -type d -name "[directory]" # find a directory in a directory

grep [string] [file]                         # search for a string in a file
grep -r [string] [directory]                 # search for a string, recursively in a directory
grep -i [string] [file]                      # search for a string, ignore case-sensitivity
grep -v [string] [file]                      # search for a string, that does not match the pattern

```


## Terminal shortcuts

```bash
Tab                                      # autocomplete the command/path
Ctrl + C                                 # cancel the current command
Ctrl + A                                 # move to the beginning of the line
Ctrl + E                                 # move to the end of the line
Option + Left/Right                      # move to the beginning/end of the word
⌘ + T                                    # create a new tab
⌘ + W                                    # close the current tab
⌘ + 1-8                                  # switch to the nth tab
```