Overview

Cheat sheet

Every command from the shell workshop (and a few handy extras). Commands marked ⚠️ can overwrite or delete files. Read before you run!

❓ Forgot an option? Ask the program itself: CMD --help for a short summary, man CMD for the full manual (no man in Git Bash).

Reading the prompt

user@gnugen:~ $
  • user: your username
  • gnugen: the computer’s name (Windows shows MINGW64 instead, you are in Git Bash)
  • ~: the folder you are in (~ = your home folder)
  • $: type your command after it, press Enter to run
Command What it does Example
pwd print working directory (where am I) pwd
ls list files in the current folder ls
ls -a also list hidden files (starting with .) ls -a
ls -l detailed list (permissions, size, date) ls -l
ls FOLDER list another folder ls Documents/
cd FOLDER change into a folder cd Documents
cd .. go up one folder cd ..
cd go to your home folder cd
cd ~ go to your home folder cd ~
cd - go back to the previous folder cd -

Paths

/home/user/Documents        absolute: starts at /, works from anywhere
Documents                   relative: starts from where you are
..                          the parent folder
.                           the current folder
~                           your home folder

On Git Bash, Windows paths are written in UNIX style: C:\Users\you = /c/Users/you.

Files and folders

Command What it does Example
mkdir NAME create a folder mkdir project
touch FILE create an empty file touch notes.txt
cat FILE print a file’s content cat notes.txt
less FILE scroll through a file (q quits) less notes.txt
nano FILE simple in-terminal text editor nano notes.txt
cp SRC DEST copy. ⚠️ overwrites DEST silently cp 1.txt 2.txt
mv OLD NEW rename or move. ⚠️ overwrites silently mv notes.txt archive/
rm FILE delete a file. ⚠️ no trash bin, never asks are you sure? rm notes.txt
rm -r FOLDER delete a folder and everything inside. ⚠️ gone forever rm -r project
start FILE open a file with its default program (Windows) start notes.txt
xdg-open FILE open a file with its default program (Linux) xdg-open notes.txt
open FILE open a file with its default program (macOS) open notes.txt

nano shortcuts: save ctrl + o (⚠️ overwrites the file with what you see), exit ctrl + x. ^ in the menu means ctrl.

Text, pipes and redirection

Command What it does Example
echo TEXT print text echo hello
echo TEXT > FILE write text into a file. ⚠️ overwrites the whole file echo hi > hi.txt
echo TEXT >> FILE append text at the end of a file echo more >> hi.txt
CMD1 | CMD2 pipe: output of CMD1 becomes input of CMD2 ls | wc -l
wc -l count lines ls | wc -l

Never point > at a file you care about. It replaces the file’s content without asking, and without a trash bin. Keep experiments inside a playground folder.

Variables

Command What it does Example
name="value" set a variable (no spaces around =) name="ado"
echo $name read a variable echo $name
echo $HOME your home folder, the long name for ~ echo $HOME
env list all environment variables env

Errors and return codes

Command What it does Example
echo $? return code of the last command echo $?
  • 0 = success
  • anything else = error (e.g. 1 = general failure, 127 = command not found)
  • no output usually means success too (programs stay quiet when happy)

Tips and tricks

Keys / Command What it does
Tab complete file and folder names while typing
↑ / ↓ browse your previous commands
ctrl + r search through your previous commands (macOS: may not work in the default zsh)
ctrl + c stop the command that is currently running
clear wipe the terminal screen
man CMD the manual of a command (Linux/macOS, not in Git Bash)
CMD --help quick help for most commands

Windows / Git Bash

Command What it does Example
explorer . open File Explorer at the current folder explorer .
notepad launch Notepad (some Windows programs start by plain name when on the PATH) notepad
start APP launch any Windows program, even off the PATH (terminal version of the Start menu) start firefox
start FILE open a file with its default program start notes.txt
notepad FILE edit a file with Notepad notepad notes.txt
C:\Users\you is written /c/Users/you in Git Bash cd /c/Users/you