Bash Cheat Sheet

Searchable reference for everyday Bash commands.

CommandDescription
ls -laList files including hidden, long format
ls -lhSSort by size, human-readable
cd <dir>Change directory
cd -Jump to previous directory
pwdPrint working directory
tree -L 2Show directory tree, depth 2
stat <file>Show file metadata (size, perms, mtime)
file <path>Detect file type by content
mkdir -p a/b/cMake nested directories
rm -rf <dir>Remove directory recursively
cp -r <src> <dst>Copy directory recursively
mv <src> <dst>Move / rename
ln -s <target> <link>Create symbolic link
touch <file>Create empty file or bump mtime
cat <file>Print file contents
less <file>Page through a file
head -n 20 <file>First 20 lines
tail -f <file>Follow file output
tail -n +2 fSkip first line (e.g. CSV header)
wc -l <file>Count lines
sort -u <file>Sort and de-duplicate
uniq -cGroup identical adjacent lines with counts
grep -r 'pat' .Recursive grep
grep -nEi 'pat' fLine numbers, ERE, case-insensitive
grep -v 'pat' fInvert match (lines NOT matching)
rg 'pat'ripgrep — fast recursive search
find . -name '*.cs'Find files by name
find . -mtime -1Files modified in last 24h
find . -type f -size +10MFiles larger than 10 MB
sed 's/foo/bar/g' fStream edit (replace globally)
sed -i 's/foo/bar/g' fEdit file in-place
awk '{print $1}' fPrint first column
awk -F, '{sum+=$2} END{print sum}' fSum a CSV column
xargs -n1 -P4 cmdRun cmd in parallel, 4 at a time
tee -a <file>Pipe + append to file (and stdout)
cut -d: -f1 /etc/passwdSlice columns by delimiter
chmod 755 <file>Set file permissions
chmod +x <file>Make executable
chown user:group fChange file owner
umask 022Default permission mask
ps aux | grep appFind running process
pgrep -f appPID of process by name pattern
kill -9 <pid>Force-kill process
killall <name>Kill all by name
top / htopLive process viewer
nohup cmd > out.log 2>&1 &Detach from terminal
jobs ; bg ; fg %1Background / foreground jobs
df -hDisk space (human readable)
du -sh <dir>Folder size
du -sh * | sort -hLargest items in this directory
free -hMemory in human units
uname -aKernel / arch / hostname
uptimeLoad average and uptime
tar -czf a.tgz d/Create gzipped tar
tar -xzf a.tgzExtract gzipped tar
tar -tzf a.tgzList contents of tarball
zip -r a.zip d/Create zip archive
unzip a.zipExtract zip archive
curl -fsSL urlQuietly fetch and pipe
curl -I urlHEAD request — headers only
curl -o file urlDownload to file
wget urlDownload a URL
ssh user@hostSSH into host
scp f user@host:/pCopy over SSH
rsync -avz src/ host:dst/Sync directories (compressed)
nc -zv host 443TCP port check
dig +short example.comDNS lookup, short form
ss -tulpnList listening sockets
export VAR=valueSet environment variable
unset VARRemove environment variable
env | sortList env vars, sorted
history | grep cmdSearch shell history
!!Re-run last command
!$Last argument of previous command
man <cmd>Show command manual
type -a <cmd>Where does this command come from?

About this tool

Common file, process, archive and shell commands with one-line descriptions.

An unhandled error has occurred. Reload ×