Terminal Cheatsheet

Bash and terminal cheatsheet covering navigation, file operations, text processing, pipes, process management, permissions, and network tools.

Updated September 15, 2026

bashshelllinuxterminalcommand-line
CommandAction
pwdPrint current directory
cd ~Go home
cd -Go to previous directory
cd ..Go up one level
ls -laList all files with details
ls -lhHuman-readable file sizes
ls -ltSort by modification time
pushd <dir>Push dir onto stack and cd
popdPop dir from stack and cd
dirsShow directory stack

Advertisement

File Operations

CommandAction
cp file destCopy file
cp -r dir destCopy directory recursively
mv file destMove or rename
rm fileDelete file
rm -rf dirDelete directory recursively
mkdir -p a/b/cCreate nested directories
touch fileCreate empty file or update timestamp
ln -s target linkCreate symbolic link
find . -name "*.py"Find files by name pattern
find . -type f -mtime -7Files modified in last 7 days
find . -size +10MFiles larger than 10MB
du -sh *Directory sizes
df -hDisk usage by filesystem
stat fileDetailed file metadata

Text Processing

CommandAction
cat filePrint file contents
less filePaginate file (q to quit)
head -n 20 fileFirst 20 lines
tail -n 20 fileLast 20 lines
tail -f fileFollow file (live updates)
grep "pattern" fileSearch for pattern
grep -r "pattern" .Recursive search
grep -i "pattern"Case-insensitive
grep -v "pattern"Invert: lines NOT matching
grep -n "pattern"Show line numbers
grep -c "pattern"Count matching lines
wc -l fileCount lines
wc -w fileCount words
sort fileSort lines alphabetically
sort -nNumeric sort
sort -rReverse sort
uniqRemove duplicate adjacent lines
uniq -cCount occurrences
cut -d: -f1 fileCut field 1 with : delimiter
awk '{print $1}' filePrint first field
awk -F: '{print $1, $3}'Custom delimiter, multiple fields
sed 's/old/new/g' fileReplace text (in output)
sed -i 's/old/new/g' fileReplace text in-place
tr 'a-z' 'A-Z'Translate characters

Pipes and Redirection

SyntaxAction
cmd1 | cmd2Pipe stdout of cmd1 to cmd2
cmd > fileRedirect stdout to file (overwrite)
cmd >> fileRedirect stdout to file (append)
cmd 2> fileRedirect stderr to file
cmd 2>&1Redirect stderr to stdout
cmd &> fileRedirect both stdout and stderr
cmd < fileUse file as stdin
cmd | tee filePrint and also save to file
cmd1 && cmd2Run cmd2 only if cmd1 succeeds
cmd1 || cmd2Run cmd2 only if cmd1 fails
cmd1 ; cmd2Run cmd2 regardless of cmd1 result

Advertisement

Process Management

CommandAction
cmd &Run command in background
jobsList background jobs
fg %1Bring job 1 to foreground
bg %1Resume job 1 in background
Ctrl+ZSuspend current process
Ctrl+CKill current process
ps auxList all processes
ps aux | grep nameFind process by name
topInteractive process viewer
htopBetter interactive viewer (if installed)
kill <pid>Send SIGTERM to process
kill -9 <pid>Send SIGKILL (force)
killall nameKill all processes by name
pkill nameKill processes matching name
nohup cmd &Run command immune to hangup

Permissions

CommandAction
chmod 755 filerwxr-xr-x (owner rwx, others r-x)
chmod 644 filerw-r--r--
chmod +x fileMake executable
chmod -R 755 dirRecursive
chown user:group fileChange owner and group
chown -R user dirRecursive ownership change
umask 022Default permission mask

Permission bits: 4 = read, 2 = write, 1 = execute. Add for each group (owner/group/others).


Archives

tar -czf archive.tar.gz dir/     # create gzip archive
tar -xzf archive.tar.gz          # extract gzip archive
tar -cjf archive.tar.bz2 dir/   # create bzip2 archive
tar -xjf archive.tar.bz2        # extract bzip2
tar -tf archive.tar.gz           # list contents without extracting
gzip file                        # compress file -> file.gz
gunzip file.gz                   # decompress
zip -r archive.zip dir/          # zip directory
unzip archive.zip                # unzip

Network

CommandAction
curl https://urlFetch URL
curl -O urlDownload file keeping name
curl -L urlFollow redirects
curl -H "Auth: token" urlCustom header
curl -X POST -d '{}' urlPOST with body
wget urlDownload file
ssh user@hostSSH login
ssh -p 2222 user@hostSSH on custom port
scp file user@host:/pathCopy file to remote
scp user@host:/path fileCopy file from remote
ping hostTest connectivity
traceroute hostTrace network path
netstat -tulnpOpen ports and listeners
ss -tulnpFaster alternative to netstat
nmap -sn 192.168.1.0/24Scan local network

Bash Shortcuts

ShortcutAction
Ctrl+AJump to line start
Ctrl+EJump to line end
Ctrl+KDelete from cursor to end
Ctrl+UDelete from cursor to start
Ctrl+WDelete word before cursor
Alt+.Insert last argument of previous command
Ctrl+RReverse search command history
!!Repeat last command
!$Last argument of previous command
!stringRun last command starting with string
Ctrl+LClear screen

Special Variables

VariableValue
$?Exit code of last command (0 = success)
$!PID of last background process
$$PID of current shell
$0Script name
$1, $2Script arguments
$@All arguments as separate words
$#Number of arguments
$HOMEHome directory
$PATHExecutable search path
$PWDCurrent directory
ToolsTagsRSSPrivacy PolicyTerms