Skip to content

Terminal Cheat Sheet

A comprehensive reference for every command and shortcut covered in the course. Click “Save as PDF” to download.

Navigation

pwdPrint working directory (where am I?)
cd dirnameChange into a directory
cd ..Go up one level
cd ~Go to home directory
cd -Go to previous directory
cd /Go to root directory
lsList files in current directory
ls -lLong format (permissions, size, date)
ls -aShow hidden files (dotfiles)
ls -laLong format + hidden files
ls -RList recursively (all subdirectories)

File Operations

touch file.txtCreate an empty file
mkdir dirnameCreate a directory
mkdir -p a/b/cCreate nested directories
cp source destCopy a file
cp -r srcdir/ destdir/Copy a directory recursively
mv oldname newnameRename (or move) a file
mv file.txt dir/Move file into a directory
rm file.txtDelete a file (permanent!)
rm -r dirname/Delete a directory and contents
rmdir empty-dir/Delete an empty directory only

Viewing Files

cat file.txtPrint entire file
head file.txtPrint first 10 lines
head -n 5 file.txtPrint first 5 lines
tail file.txtPrint last 10 lines
tail -n 5 file.txtPrint last 5 lines
less file.txtScrollable file viewer (q to quit)

Keyboard Shortcuts

TabAutocomplete file/command names
Up ArrowPrevious command from history
Ctrl + CCancel current command
Ctrl + LClear the screen
Ctrl + AJump to beginning of line
Ctrl + EJump to end of line
Ctrl + WDelete word before cursor
Ctrl + UDelete from cursor to start of line
Ctrl + KDelete from cursor to end of line
Ctrl + RReverse search command history
Alt + FMove cursor forward one word
Alt + BMove cursor backward one word

Piping & Redirection

command > file.txtRedirect output to file (overwrite)
command >> file.txtAppend output to file
command1 | command2Pipe: send output to next command
grep "pattern" fileSearch for text in a file
grep -i "pattern" fileCase-insensitive search
grep -c "pattern" fileCount matching lines
wc -l file.txtCount lines
wc -w file.txtCount words
sort file.txtSort lines alphabetically
sort -n file.txtSort numerically
uniqRemove adjacent duplicate lines
uniq -cCount occurrences of each line

Search & Find

find . -name "*.txt"Find files by name pattern
find . -type dFind directories only
which commandShow where a command is installed

Environment Variables

echo $HOMEPrint home directory path
echo $PATHPrint executable search path
echo $USERPrint current username
export VAR="value"Set an environment variable

Power User

*.txtWildcard: match any .txt files
file{1..5}.txtBrace expansion: file1.txt through file5.txt
$(command)Command substitution: use output as argument
cmd1 && cmd2Run cmd2 only if cmd1 succeeds
cmd1 || cmd2Run cmd2 only if cmd1 fails
!!Repeat last command
!$Last argument of previous command
alias ll="ls -la"Create a shortcut for a command

Getting Help

command --helpQuick usage summary
man commandFull manual page (q to quit)

Terminal Velocity — terminalvelocitycourse.com