Linux Commands Cheat Sheet
1Top 20 Commands
The commands you'll use 80% of the time
lsList filescdChange directorypwdPrint working directorycpCopy files/dirsmvMove or renamermRemove files/dirsmkdirCreate directorycatPrint file contentsgrepSearch text patternschmodChange permissionssudoRun as rootsshRemote logincurlTransfer data / HTTPpsList processeskillTerminate processtarArchive & compressfindSearch for filesdfDisk free spaceechoPrint text / variablesmanManual pages2File Operations
ls -laList all + permissionsls -lhSSort by sizetree -L 2Directory treecp file dstCopy filecp -r dir/ dst/Copy directorymv old newRename filemv file dir/Move to dirrm fileDelete filerm -rf dir/Delete directorymkdir -p a/b/cNested dirstouch file.txtEmpty fileln -s target linkSymbolic linkreadlink linkShow link target3Search & Find
find, Search by file attributes
find / -name '*.log'By filename patternfind . -type f -size +100MFiles over 100MBfind . -mtime -7Modified in last 7 daysfind . -type f -emptyEmpty filesfind . -perm 777Files with 777 permsfind . -name '*.tmp' -deleteFind AND deletegrep, Search inside files
grep 'text' fileBasic searchgrep -rn 'text' .Recursive + line numbersgrep -i 'text' fileCase-insensitivegrep -v 'exclude'Lines NOT matchinggrep -E 'a|b' fileRegex ORgrep -l 'text' *.pyOnly filenamesQuick lookups
locate filenameFast indexed searchwhich cmdWhere is this binary?whereis cmdBinary + man + sourcetype cmdHow shell resolves cmd4Text Manipulation
Pipeline
Read & View
cat filePrint entire fileless fileScrollable viewer (q quit)head -n 20 fileFirst 20 linestail -n 20 fileLast 20 linestail -f logfileFollow in real timeSort, Filter, Count
sort fileSort alphabeticallysort -n -r fileNumeric, reverseduniqRemove adjacent dupessort | uniq -cCount occurrenceswc -l fileCount lineswc -w fileCount wordscut -d',' -f1,3Extract CSV columnstr 'A-Z' 'a-z'Lowercasesed, Stream editor
sed 's/old/new/g' fReplace all occurrencessed -i 's/old/new/g' fIn-place editsed -n '5,10p' fPrint lines 5, 10sed '/^$/d' fDelete empty linesawk, Column processor
awk '{print $1, $3}'Print columns 1 and 3awk -F: '{print $1}'Custom delimiterawk '$3>100'Filter by valueawk '{s+=$1} END{print s}'Sum columnawk 'NR==5,NR==10'Print lines 5-105Network Commands
HTTP & Downloads
curl urlFetch contentcurl -I urlHeaders onlycurl -o file urlDownload to filecurl -X POST -d 'data' urlPOST requestwget urlDownload filewget -q -O - urlDownload to stdoutDNS & Connectivity
ping -c 4 hostTest reachabilitytraceroute hostTrace routedig domainDNS lookupnslookup domainDNS querycurl ifconfig.meYour public IPSSH & Transfer
ssh user@hostRemote loginssh -i key user@hostLogin with keyscp file user@h:/pathCopy to remotersync -avz src/ h:dst/Sync efficientlyPorts & Sockets
ss -tulnpListening ports + PIDslsof -i :8080What's on port 8080ip addrShow IP addressesip routeShow routing table6Process & System
$ ps aux | head -3
USER PID %CPU %MEM COMMAND
root 1 0.0 0.1 /sbin/init
root 2 0.0 0.0 [kthreadd]
View Processes
ps auxAll processesps aux | grep nameFilter by nametopLive monitorhtopBetter monitor (install)pgrep -f nameGet PID by nameKill & Signal
kill PIDTERM (15)
Graceful
kill -9 PIDKILL (9)
Force
kill -1 PIDHUP (1)
Reload
killall nameKill all by namepkill -f patternKill by patternBackground Jobs
cmd &Run in backgroundnohup cmd &Survive logoutjobsList background jobsfg %1Bring to foregroundbg %1Resume in backgroundSystem Info
uname -aKernel infouptimeUptime + loadfree -hMemory usagelscpuCPU infohostnameMachine namedateDate & time7Permission Commands
chmod 755 filerwxr-xr-x (scripts, dirs)chmod 644 filerw-r--r-- (regular files)chmod 600 filerw------- (secrets)chmod +x fileAdd execute permissionchmod -R 755 dir/Recursive permission setOwnership
chown user fileChange ownerchown user:group fileChange owner + groupchown -R user dir/Recursivechgrp group fileChange group onlySudo & Users
sudo cmdRun as rootsudo -u user cmdRun as another usersudo -iRoot interactive shellwhoamiCurrent usernameidUID, GID, groups8Disk & Storage
Space Usage
df -hFilesystem disk usagedu -sh *Size of each item heredu -sh /pathTotal size of pathdu -h --max-depth=1 /Top-level dir sizesncdu /Interactive analyzerDevices
lsblkList block devicesfdisk -lDisk partitionsmount /dev/sdb1 /mntMount partitionumount /mntUnmountblkidUUIDs + FS types9Archive & Compress
tar syntax breakdown
tar -czf out.tar.gz dir/Create gzip archivetar -xzf file.tar.gzExtract gzip archivetar -xzf f.tar.gz -C /dstExtract to directorytar -tzf file.tar.gzList contents onlytar -cjf out.tar.bz2 dir/Create bzip2 archiveOther formats
gzip fileCompressgunzip f.gzDecompresszip -r o.zip dir/Create zipunzip f.zipExtract zip10Services & Cron
systemctl, Service Control
systemctl start svcStart servicesystemctl stop svcStop servicesystemctl restart svcRestart servicesystemctl status svcCheck statussystemctl enable svcStart on bootsystemctl disable svcDon't start on bootLogs
journalctl -u svcService logsjournalctl -fFollow all logsdmesg | tailKernel messagestail -f /var/log/syslogSystem logCron Scheduling
*/5 * * * *Every 5 min0 * * * *Every hour0 2 * * *Daily 2 AM0 0 * * 0Weekly Sun30 9 * * 1-5Weekdays 9:30crontab -e to edit, crontab -l to list
11Power One-Liners
Copy-paste solutions to common problems
Find large files
find / -type f -size +500M -exec ls -lh {} \;Kill port 3000
lsof -ti :3000 | xargs kill -9Count files in dir
find . -type f | wc -lTop 10 largest dirs
du -sh */ | sort -rh | head -10Replace in all files
find . -name '*.py' -exec sed -i 's/old/new/g' {} +Watch log for errors
tail -f /var/log/syslog | grep -i errorDisk hogs
du -h --max-depth=1 / 2>/dev/null | sort -rh | headEmpty all .log files
find . -name '*.log' -exec truncate -s 0 {} +List open ports
ss -tulnp | grep LISTENUnique IPs from log
awk '{print $1}' access.log | sort -u | wc -l12Shell Shortcuts
History Tricks
!!Repeat last commandsudo !!Last cmd as root!$Last argument!cmdLast cmd starting with...The Complete Linux Commands Cheat Sheet
This Linux commands cheat sheet is a task-oriented reference for every command you'll need on the command line. Instead of alphabetical lists, commands are organized by what you're trying to do, find files, search text, manage processes, transfer data, and more.
Our Linux command line cheat sheet covers the top 20 most-used commands, file operations (copy, move, delete, link), search tools (find, grep, locate), text processing (sed, awk, sort, cut), networking (curl, SSH, rsync, ports), process management (ps, kill, jobs), permissions (chmod, chown, sudo), disk usage, archive commands with tar syntax breakdowns, systemd services, cron scheduling, and copy-paste power one-liners for common tasks.
Whether you're a beginner learning the basic Linux commands or a sysadmin looking for a quick reference, this cheat sheet puts every essential command in one view , organized by task, with real syntax you can copy-paste directly into your terminal.
Linux Commands FAQ
What are the most used Linux commands?expand_more
The top 20 most used Linux commands are: ls, cd, pwd, cp, mv, rm, mkdir, cat, grep, chmod, sudo, ssh, curl, ps, kill, tar, find, df, echo, and man. These cover file management, text search, permissions, networking, processes, and system info, roughly 80% of daily command-line tasks.
How do I find files in Linux?expand_more
Use 'find' to search by file attributes: 'find / -name "*.log"' searches by name, 'find . -size +100M' finds large files, 'find . -mtime -7' finds recently modified files. Use 'grep -rn "text" .' to search inside files. Use 'locate filename' for fast indexed searches (requires updatedb).
What is the difference between grep, sed, and awk?expand_more
grep searches for patterns and prints matching lines, use it to find things. sed is a stream editor that transforms text, use it for find-and-replace operations. awk processes columnar data, use it to extract, filter, and compute on specific fields. A common pipeline chains all three: grep to filter, sed to transform, awk to format output.
How do I check what is using a port in Linux?expand_more
Use 'ss -tulnp' to see all listening ports with their process IDs, or 'lsof -i :8080' to check a specific port. 'netstat -tulnp' does the same but is considered legacy. These commands typically require sudo for full output.
How do I compress and extract files in Linux?expand_more
For tar.gz: 'tar -czf archive.tar.gz dir/' to create, 'tar -xzf archive.tar.gz' to extract. The flags mean: c=create, x=extract, z=gzip, f=file. For zip: 'zip -r archive.zip dir/' to create, 'unzip archive.zip' to extract. Use 'tar -tzf archive.tar.gz' to list contents without extracting.
What are the most useful Linux one-liners?expand_more
Essential one-liners: 'lsof -ti :3000 | xargs kill -9' (kill process on port), 'du -sh */ | sort -rh | head -10' (top 10 largest dirs), 'find . -name "*.log" -exec truncate -s 0 {} +' (empty all log files), 'tail -f /var/log/syslog | grep -i error' (watch for errors in real time), and 'awk "{print $1}" access.log | sort -u | wc -l' (count unique IPs).
Ready to ace your technical interview?
Practice with an AI interviewer that tests your Linux knowledge, coding skills, and problem-solving ability in real time.
Try Crackr freearrow_forwardContinue learning
Linux Cheat Sheet
Concepts + commands with visual diagrams
Subnet Cheat Sheet
CIDR, subnet masks, VLSM reference
System Design Cheat Sheet
Load balancing, caching, databases
Big O Cheat Sheet
Time & space complexity reference
Algorithm Visualizers
See DSA in action
Company Questions
Real interview questions by company