Linux Commands Cheat Sheet
Quick reference for essential Linux commands — files, permissions, networking, and more
ls -laList all files including hidden, with detailed info
ls -lhSList files sorted by size, human-readable
cd -Switch to the previous directory
pwdPrint current working directory
mkdir -p dir1/dir2/dir3Create nested directories recursively
cp -r src/ dest/Copy directory recursively
mv old newMove or rename a file/directory
rm -rf dir/Remove directory and contents recursively (use with caution)
touch file.txtCreate an empty file or update its timestamp
ln -s target linkCreate a symbolic link
find / -name '*.log' -mtime +7Find .log files modified more than 7 days ago
find . -type f -size +100MFind files larger than 100MB
locate filenameQuickly find files by name (uses pre-built index)
tree -L 2Display directory tree, 2 levels deep
stat file.txtDisplay detailed file information (size, permissions, timestamps)
file document.pdfDetermine the type of a file
cat file.txtDisplay entire file contents
less file.txtView file with pagination (q to quit)
head -n 20 file.txtShow first 20 lines of a file
tail -f /var/log/syslogFollow log file output in real time
realpath file.txtPrint the resolved absolute path
chmod 755 script.shSet rwxr-xr-x permissions (owner full, others read+execute)
chmod +x script.shAdd execute permission for all users
chmod -R 644 dir/Recursively set rw-r--r-- on all files in directory
chmod u+s executableSet SUID bit — run as file owner
chown user:group fileChange file owner and group
chown -R user:group dir/Recursively change ownership of directory
chgrp devs file.txtChange file group ownership
umask 022Set default permission mask for new files
getfacl file.txtDisplay Access Control List for a file
setfacl -m u:user:rw file.txtSet ACL to grant a user read/write access
grep -rn 'pattern' dir/Recursively search for pattern with line numbers
grep -i 'error' log.txtCase-insensitive search in a file
grep -v 'debug' log.txtShow lines that do NOT match the pattern
grep -c 'error' log.txtCount matching lines
sed 's/old/new/g' file.txtReplace all occurrences of 'old' with 'new'
sed -i '10d' file.txtDelete line 10 in-place
sed -n '5,10p' file.txtPrint only lines 5 through 10
awk '{print $1, $3}' file.txtPrint 1st and 3rd columns
awk -F: '{print $1}' /etc/passwdPrint first field using : as delimiter
sort -u file.txtSort and remove duplicate lines
sort -t: -k3 -n /etc/passwdSort by 3rd field numerically, delimited by :
uniq -cCount consecutive duplicate lines
cut -d: -f1,3 /etc/passwdExtract fields 1 and 3 with : delimiter
tr 'a-z' 'A-Z' < file.txtConvert lowercase to uppercase
wc -l file.txtCount lines in a file
diff file1 file2Show differences between two files
tee output.txtRead stdin and write to both stdout and file
xargs -I {} cp {} /dest/Execute command for each line of input
ps auxList all running processes with details
ps aux | grep nginxFind processes matching a name
topInteractive real-time process viewer
htopEnhanced interactive process viewer (install separately)
kill <pid>Send SIGTERM to a process (graceful shutdown)
kill -9 <pid>Force kill a process (SIGKILL)
killall nginxKill all processes by name
pkill -f 'pattern'Kill processes matching a pattern
bg %1Resume suspended job in background
fg %1Bring background job to foreground
jobsList background and suspended jobs
nohup ./script.sh &Run command immune to hangups in background
nice -n 10 ./cpu-heavy.shStart process with lower priority
renice -n 5 -p <pid>Change priority of a running process
pgrep -la nginxList PIDs and names of matching processes
lsof -i :8080List processes using port 8080
curl -I https://example.comFetch HTTP headers only
curl -o file.zip https://example.com/file.zipDownload a file
curl -X POST -d '{"key":"val"}' -H 'Content-Type: application/json' urlSend a JSON POST request
wget -r -np https://example.com/Recursively download a website
ping -c 4 google.comSend 4 ICMP echo requests
traceroute google.comTrace the route packets take to a host
ss -tulnpShow listening TCP/UDP sockets with process info
netstat -tulnpList listening ports and associated processes
ip addr showShow all network interfaces and IP addresses
ip route showDisplay the routing table
dig example.comDNS lookup with detailed information
nslookup example.comQuery DNS for a domain
scp file.txt user@host:/path/Copy file to remote host via SSH
rsync -avz src/ user@host:/dest/Sync files to remote with compression
ssh user@hostConnect to remote host via SSH
ssh -L 8080:localhost:80 user@hostCreate SSH tunnel (local port forwarding)
nc -zv host 22Test if a port is open on a host
uname -aDisplay all system information
hostnameShow or set the system hostname
uptimeShow how long the system has been running
whoamiPrint the current username
idDisplay user ID, group ID, and groups
lsb_release -aShow Linux distribution information
cat /etc/os-releaseDisplay OS release details
free -hShow memory usage in human-readable format
lscpuDisplay CPU architecture information
lsblkList all block devices (disks and partitions)
dmesg | tail -20Show last 20 kernel messages
dateDisplay current date and time
timedatectlShow and configure system time settings
envPrint all environment variables
printenv PATHPrint a specific environment variable
tar -czf archive.tar.gz dir/Create gzip-compressed tar archive
tar -xzf archive.tar.gzExtract gzip tar archive
tar -cjf archive.tar.bz2 dir/Create bzip2-compressed tar archive
tar -xjf archive.tar.bz2Extract bzip2 tar archive
tar -tf archive.tar.gzList contents of tar archive without extracting
gzip file.txtCompress file (replaces original with file.txt.gz)
gunzip file.txt.gzDecompress gzip file
zip -r archive.zip dir/Create zip archive of a directory
unzip archive.zip -d /dest/Extract zip archive to destination
xz file.txtCompress file with xz (high compression ratio)
unxz file.txt.xzDecompress xz file
zcat file.gzView contents of a gzip file without extracting
sudo useradd -m -s /bin/bash userCreate user with home directory and bash shell
sudo userdel -r userDelete user and their home directory
sudo usermod -aG docker userAdd user to a group (append)
sudo passwd userSet or change a user's password
su - userSwitch to another user with login shell
sudo -iOpen root shell
groups userShow groups a user belongs to
whoShow who is currently logged in
wShow logged-in users and their activity
lastShow recent login history
sudo visudoSafely edit the sudoers file
df -hShow disk space usage for all mounted filesystems
du -sh dir/Show total size of a directory
du -h --max-depth=1Show sizes of immediate subdirectories
du -ah . | sort -rh | head -20Find 20 largest files/dirs in current directory
sudo mount /dev/sdb1 /mntMount a partition
sudo umount /mntUnmount a filesystem
sudo fdisk -lList all disk partitions
lsblk -fList block devices with filesystem info
blkidDisplay block device attributes (UUID, type)
ncduInteractive disk usage analyzer (install separately)
sudo apt updateUpdate package index (Debian/Ubuntu)
sudo apt upgradeUpgrade all installed packages
sudo apt install <package>Install a package
sudo apt remove <package>Remove a package (keep config)
sudo apt purge <package>Remove a package and its configuration
sudo apt autoremoveRemove unused dependency packages
apt search <keyword>Search for packages by keyword
apt show <package>Show detailed package information
dpkg -l | grep <package>Check if a package is installed
dpkg -i package.debInstall a .deb package file
sudo snap install <package>Install a snap package
snap listList installed snap packages
Commands shown may vary slightly between Linux distributions.
Related Tools
JSON Formatter
Format, validate, and minify JSON data with syntax highlighting
JSON / YAML / TOML Converter
Convert between JSON, YAML, and TOML — validate, format, minify, and download in your browser
Color Scheme Generator
Generate harmonious color palettes — complementary, triadic, analogous, and more
Git Cheat Sheet
Quick reference for Git commands — branching, merging, rebasing, and workflows
Linux Commands Cheat Sheet
A free, searchable Linux command cheat sheet with the most useful commands, flags, and shortcuts in one place. Quickly look up syntax, copy commands, and learn the Linux terminal faster — perfect for beginners and a handy reference for experienced users.
FAQ
- Is this Linux command cheat sheet free?
- Yes. The entire cheat sheet is free to browse and copy from, with no sign-up required.
- Can I search for a specific command?
- Yes. Use the search to filter the Linux command commands instantly and jump straight to the syntax you need.
- Who is the Linux command cheat sheet for?
- It suits everyone from newcomers learning the Linux terminal to power users who want a quick reminder of less-used flags and shortcuts.