Skip to main content

Terminal Cheat Sheet

SHORTCUTS

Key/CommandDescription
Ctrl + AGo to the beginning of the line you are currently typing on.
Ctrl + EGo to the end of the line you are currently typing on.
Ctrl + CKill whatever you are running. Also clears everything on current line
TabAuto-complete files and folder names

CORE COMMANDS

Key/CommandDescription
cd [folder]Change directory e.g. `cd Documents`
cdHome directory
cd /Root of drive
cd -Previous directory
lsShort listing
ls -lLong listing
ls -aListing incl. hidden files
ls -lhLong listing with Human readable file sizes
ls -REntire content of folder recursively
sudo [command]Run command with the security privileges of the superuser (Super User DO)
nano [file]Opens the file using the nano editor

COMMAND HISTORY

Key/CommandDescription
history nShows the stuff typed – add a number to limit the last n items
arrow key upScrolls through last commands typed

FILE MANAGEMENT

Key/CommandDescription
touch [file]Create a new file
pwdFull path to working directory
.Current folder, e.g. `ls .`
..Parent/enclosing directory, e.g. `ls ..`
ls -l ..Long listing of parent directory
cd ../../Move 2 levels up
rm [file]Remove a file, e.g. `rm data.tmp`
rm -i [file]Remove with confirmation
rm -r [dir]Remove a directory and contents
rm -f [file]Force removal without confirmation
cp [file] [newfile]Copy file to file
cp [file] [dir]Copy file to directory
mv [file] [new filename]Move/Rename, e.g. `mv file1.ad /tmp`

DIRECTORY MANAGEMENT

Key/CommandDescription
mkdir [dir]Create new directory
mkdir -p [dir]/[dir]Create nested directories
rmdir [dir]Remove directory ( only operates on empty directories )
rm -R [dir]Remove directory and contents
less [file]Output file content delivered in screensize chunks

HELP

Key/CommandDescription
[command] -hOffers help
[command] --helpOffers help
info [command]Offers help
man [command]Show the help manual for [command]

CREATE A REPOSITORY

Key/CommandDescription
git init [project name]create a new local repository
git clone my_urldownload from an existing repository

OBSERVE YOUR REPOSITORY

Key/CommandDescription
git statuslist new or modified files not yet committed
git diffshow the changes to files not yet staged
git diff --cachedshow the changes to staged files
git diff HEADshow all staged and unstaged file changes
git diff commit1 commit2show the changes between two commit ids
git blame [file]list the change dates and authors for a file
git show [commit]: [file]show the file changes for a commit id and/ or file
git logshow full change history
git log -p [file/directory]show change history for file/directory including diffs

WORKING WITH BRANCHES

Key/CommandDescription
git branchlist of local branches
git branch -avlist all branches, local and remote
git checkout my_branchswitch to a branch, my_branch, and update working directory
git branch new_branchcreate a new branch called "new_branch"
git branch -d my_branchdelete the branch called "my_branch"
git checkout branch_b + git merge branch_amerge branch_a into branch_b
git tag my_tagtag the current commit

MAKE A CHANGE

Key/CommandDescription
git add [file]stages the file, ready for commit
git add .stage all changed files, ready for commit
git commit -m "commit message"commit all staged files to versioned history
git commit -am "commit message"commit all your tracked files to versioned history
git reset [file]unstages file, keeping the file changes
git reset --hardrevert everything to the last commit

SYNCHRONIZE

Key/CommandDescription
git fetchgit the latest changes from origin (no merge)
git pullfetch the latest changes from origin and merge
git pull --rebasefetch the latest changes from origin and rebase
git pushpush local changes to the origin