Top 100 Linux Commands Cheat Sheet for Power Users

Top 100 Linux Commands Cheat Sheet for Power Users

Welcome to the ultimate Linux commands cheat sheet, designed for beginners and seasoned sysadmins alike. This comprehensive guide covers 100 of the most essential Linux commands, organized by category, with clear descriptions, practical examples, and tips for chaining commands to streamline your workflows. Whether you’re managing files, monitoring systems, or scripting automation, this cheat sheet from SquidHacker is your go-to resource for mastering the Linux terminal.

  • File and Directory Management
    • Commands for creating, moving, copying, and deleting files and directories, plus tools for searching and archiving.
  • Text Processing
    • Tools for viewing, editing, searching, and manipulating text files, ideal for log analysis and data parsing.
  • System Information
    • Commands to monitor system resources, check hardware details, and track running processes.
  • Network
    • Utilities for managing network connections, testing connectivity, and transferring files securely.
  • User and Permission Management
    • Commands to create, modify, and delete user accounts, as well as manage file permissions.
  • Package Management
    • Tools for installing, updating, and managing software packages across different Linux distributions.
  • Process Management
    • Commands to monitor, prioritize, and terminate processes for efficient system performance.
  • Disk and Filesystem
    • Utilities for managing disks, partitions, and filesystems, including mounting and formatting.
  • Shell and Scripting
    • Commands for scripting, environment management, and creating shortcuts to streamline workflows.
  • Other Utilities
    • Miscellaneous tools for accessing manuals, clearing the terminal, and monitoring changes.

Introduction to Command Chaining

Chaining commands in Linux is a powerful way to combine multiple operations for efficient, automated workflows. By linking commands, you can process data, handle errors, and execute complex tasks in a single line. Here are the key methods:

  • Piping (|): Passes the output of one command as input to another.
    Example: ls -l | grep "txt" lists files and filters those containing “txt”.
  • Redirection (>, >>, <): Redirects input/output to/from files.
    • >: Overwrites a file with output. Example: echo "Hello" > hello.txt.
    • >>: Appends output to a file. Example: echo "World" >> hello.txt.
    • <: Reads input from a file. Example: sort < unsorted.txt.
  • Logical Operators (&&, ||):
    • &&: Runs the second command if the first succeeds. Example: mkdir newdir && cd newdir.
    • ||: Runs the second command if the first fails. Example: ping -c 1 google.com || echo "No internet".

Commands by Category

1. File and Directory Management

CommandDescriptionPurposeBasic ExampleChaining Example
lsLists directory contentsView files and foldersls -lls -l | grep "txt" (filters files by pattern)
cdChanges current directoryNavigate filesystemcd /home/usercd /tmp && touch temp.txt (changes directory and creates file)
pwdPrints working directoryConfirm current locationpwdpwd | xargs echo "Current dir:" (displays with prefix)
mkdirCreates new directoryOrganize filesmkdir newfoldermkdir logs && cd logs (creates and enters directory)
rmdirRemoves empty directoryClean up unused foldersrmdir oldfolderrmdir oldfolder || echo "Directory not empty" (handles errors)
touchCreates empty file or updates timestampInitialize filestouch file.txttouch file.txt && echo "Data" > file.txt (creates and writes to file)
cpCopies files/directoriesDuplicate datacp file.txt copy.txtcp file.txt backup/ | xargs ls (copies and lists)
mvMoves/renames filesRelocate or renamemv file.txt newfile.txtmv file.txt /tmp && ls /tmp (moves and verifies)
rmDeletes files/directoriesRemove unwanted datarm -r folderrm file.txt || echo "File not found" (handles errors)
findSearches for filesLocate specific filesfind /home -name "*.txt"find . -type f -exec grep "error" {} \; (searches text in files)
locateFinds files using databaseQuick file searchlocate document.pdflocate *.pdf | xargs ls (lists found PDFs)
duEstimates file space usageCheck disk usagedu -sh folderdu -sh * | sort -h (sorts directories by size)
dfReports disk space usageMonitor free spacedf -hdf -h | grep "/dev/sda" (filters specific disk)
tarArchives filesBundle filestar -cvf archive.tar foldertar -cvf archive.tar folder | xargs ls -l (archives and lists)
gzipCompresses filesReduce file sizegzip file.txtgzip file.txt && ls *.gz (compresses and lists)
gunzipDecompresses filesRestore compressed filesgunzip file.txt.gzgunzip file.txt.gz && cat file.txt (decompresses and displays)
zipCompresses files into zipCreate zip archiveszip archive.zip file.txtzip archive.zip *.txt | xargs ls (zips and lists)
unzipExtracts zip filesAccess zipped contentunzip archive.zipunzip archive.zip && ls (extracts and lists)
lnCreates linksShare files via linksln -s file.txt linkln -s file.txt link && ls -l (creates link and verifies)
fileDetermines file typeIdentify file formatsfile document.pdffile * | grep "PDF" (filters PDF files)

2. Text Processing

CommandDescriptionPurposeBasic ExampleChaining Example
catDisplays file contentsView or concatenate filescat file.txtcat file.txt | grep "error" (filters lines)
lessViews file content page-wiseRead large filesless log.txtless log.txt | grep "error" (searches while viewing)
moreDisplays file content page-wiseSimilar to lessmore log.txtmore log.txt | head -n 10 (shows first 10 lines)
headShows first lines of filePreview file starthead -n 5 file.txthead file.txt | grep "start" (filters first lines)
tailShows last lines of fileMonitor file endtail -n 5 file.txttail -f log.txt | grep "error" (monitors errors)
grepSearches text patternsFind specific textgrep "error" log.txtps aux | grep "process_name" (finds processes)
sedStream editor for textModify textsed 's/old/new/' file.txtcat file.txt | sed 's/error/warning/' (replaces text)
awkProcesses text patternsExtract dataawk '{print $1}' file.txtps aux | awk '{print $2}' (lists PIDs)
sortSorts linesOrganize datasort file.txtcat file.txt | sort -u (sorts uniquely)
uniqFilters repeated linesRemove duplicatesuniq file.txtsort file.txt | uniq (removes duplicates)
cutExtracts sections from linesParse delimited datacut -d',' -f1 file.csvcat file.csv | cut -d',' -f1 (extracts first column)
pasteMerges lines of filesCombine datapaste file1.txt file2.txtpaste file1.txt file2.txt | sort (merges and sorts)
wcCounts lines, words, charactersAnalyze textwc -l file.txtcat file.txt | wc -w (counts words)
trTranslates charactersModify texttr 'a-z' 'A-Z' < file.txtcat file.txt | tr '[:lower:]' '[:upper:]' (converts case)
teeWrites to file and stdoutSave and display outputls | tee output.txtls -l | tee output.txt | grep "txt" (saves and filters)

3. System Information

CommandDescriptionPurposeBasic ExampleChaining Example
unameShows system informationCheck OS detailsuname -auname -r | xargs echo "Kernel:" (displays kernel)
hostnameDisplays/sets hostnameIdentify systemhostnamehostname | xargs echo "Host:" (prefixes hostname)
uptimeShows system uptimeMonitor runtimeuptimeuptime | cut -d',' -f1 (extracts uptime)
whoamiShows current userVerify identitywhoamiwhoami | xargs echo "User:" (prefixes user)
idShows user/group IDsCheck permissionsidid | grep "uid" (filters UID)
lscpuDisplays CPU infoCheck processor detailslscpulscpu | grep "Model name" (shows CPU model)
lsblkLists block devicesView disk layoutlsblklsblk | grep "disk" (filters disks)
freeShows memory usageMonitor RAMfree -hfree -h | grep "Mem" (shows memory line)
topMonitors processesView system activitytoptop -bn1 | grep "load average" (shows load)
htopInteractive process viewerManage processeshtophtop -u user | grep "process" (filters user processes)
psLists processesCheck running tasksps auxps aux | grep "httpd" (finds httpd processes)
killTerminates processesStop taskskill 1234ps aux | grep "process" | awk '{print $2}' | xargs kill (kills process)

4. Network

CommandDescriptionPurposeBasic ExampleChaining Example
pingTests network connectivityCheck host reachabilityping -c 4 google.comping -c 1 google.com || echo "No connection" (handles failure)
ifconfigConfigures network interfacesView network settingsifconfigifconfig | grep "inet" (shows IP addresses)
ipManages network settingsModern network toolip addr showip addr show | grep "inet" (filters IPs)
netstatShows network connectionsMonitor networknetstat -tulnnetstat -tuln | grep ":80" (filters port 80)
ssInvestigates socketsView connectionsss -tulnss -tuln | grep "80" (filters port 80)
tracerouteTraces packet routesDiagnose network pathstraceroute google.comtraceroute google.com | tail -n 5 (shows last hops)
nslookupQueries DNS serversResolve domainsnslookup google.comnslookup google.com | grep "Address" (shows IPs)
digPerforms DNS lookupsDetailed DNS infodig google.comdig google.com | grep "ANSWER" (shows answers)
wgetDownloads filesFetch web contentwget http://example.com/filewget -qO- http://example.com | grep "title" (fetches and searches)
curlTransfers dataAPI/web requestscurl http://example.comcurl -s http://example.com | grep "html" (fetches silently)
scpSecurely copies filesTransfer between hostsscp file.txt user@host:/pathscp file.txt user@host:/path && ssh user@host ls (copies and lists)
sshConnects to remote hostsRemote managementssh user@hostssh user@host "ls -l" | grep "file" ( AscendingOrder:

5. User and Permission Management

CommandDescriptionPurposeBasic ExampleChaining Example
useraddCreates new userAdd accountsuseradd -m johnuseradd -m john && passwd john (adds user and sets password)
usermodModifies user accountUpdate user settingsusermod -aG sudo johnusermod -aG sudo john && groups john (adds to group and verifies)
userdelDeletes user accountRemove usersuserdel -r johnuserdel -r john || echo "User not found" (handles errors)
passwdChanges passwordsSecure accountspasswd johnpasswd john && echo "Password updated" (confirms update)
sudoRuns commands as another userExecute with privilegessudo apt updatesudo apt update && sudo apt upgrade (updates system)
suSwitches userChange identitysu - johnsu - john -c "whoami" | grep "john" (verifies user)
chownChanges file ownershipAssign ownerschown john file.txtchown john file.txt && ls -l (changes and verifies)
chmodChanges file permissionsSet access rightschmod 755 file.txtchmod 755 file.txt && ls -l (sets and verifies)
umaskSets default permissionsControl new file permissionsumask 022umask 022 && touch file.txt && ls -l (sets and tests)

6. Package Management

CommandDescriptionPurposeBasic ExampleChaining Example
aptManages Debian packagesInstall/update softwareapt updateapt update && apt install nginx (updates and installs)
yumManages RPM packagesInstall software (CentOS)yum install httpdyum update && yum install httpd (updates and installs)
dnfModern RPM package managerInstall software (Fedora)dnf install vimdnf update && dnf install vim (updates and installs)
pacmanManages Arch packagesInstall softwarepacman -S vimpacman -Syu && pacman -S vim (updates and installs)
dpkgInstalls Debian packagesManage .deb filesdpkg -i package.debdpkg -i package.deb && apt install -f (installs and fixes)

7. Process Management

CommandDescriptionPurposeBasic ExampleChaining Example
killallKills processes by nameStop multiple processeskillall firefoxkillall firefox || echo "No firefox running" (handles errors)
pkillKills processes by nameStop processespkill -9 sshdpkill sshd && echo "Processes killed" (confirms kill)
niceSets process priorityControl resource usagenice -n 10 commandnice -n 10 sleep 10 && echo "Done" (runs with priority)
reniceChanges running process priorityAdjust priorityrenice 10 1234renice 10 1234 && ps -p 1234 (changes and verifies)
bgRuns job in backgroundManage jobsbg %1jobs | grep "stopped" | xargs bg (resumes stopped jobs)
fgBrings job to foregroundManage jobsfg %1jobs | grep "running" | xargs fg (brings to foreground)
jobsLists active jobsMonitor jobsjobsjobs | grep "running" (filters running jobs)

8. Disk and Filesystem

CommandDescriptionPurposeBasic ExampleChaining Example
mountMounts filesystemsAccess disksmount /dev/sda1 /mntmount /dev/sda1 /mnt && ls /mnt (mounts and lists)
umountUnmounts filesystemsDetach disksumount /mntumount /mnt || echo "Unmount failed" (handles errors)
fdiskManages partitionsCreate partitionsfdisk /dev/sdafdisk -l | grep "/dev/sda" (lists partitions)
mkfsCreates filesystemsFormat disksmkfs.ext4 /dev/sda1mkfs.ext4 /dev/sda1 && mount /dev/sda1 /mnt (formats and mounts)
fsckChecks/repairs filesystemsFix disk errorsfsck /dev/sda1fsck /dev/sda1 || echo "Errors found" (handles errors)

9. Shell and Scripting

CommandDescriptionPurposeBasic ExampleChaining Example
echoPrints textDisplay variables/messagesecho "Hello"echo $PATH | tr ':' '\n' (splits PATH)
printfFormats textPrecise output formattingprintf "Value: %s\n" "test"printf "%s\n" *.txt | sort (lists and sorts files)
aliasCreates command shortcutsSimplify commandsalias ll='ls -l'alias ll='ls -l' && ll (sets and uses alias)
historyShows command historyReview past commandshistoryhistory | grep "git" (filters git commands)
envShows environment variablesCheck settingsenvenv | grep "PATH" (filters PATH)

10. Other Utilities

CommandDescriptionPurposeBasic ExampleChaining Example
manDisplays command manualsLearn command usageman lsman ls | less (paginates manual)
whatisShows command descriptionQuick command infowhatis lswhatis ls | grep "list" (filters description)
whereisLocates command filesFind binarieswhereis lswhereis ls | cut -d' ' -f2 (extracts path)
clearClears terminalClean screenclearls && clear (lists then clears)
watchRuns command periodicallyMonitor changeswatch -n 1 'date'watch -n 1 'df -h' | grep "/dev/sda" (monitors disk)

Notes

  • Distribution-Specific Commands: Commands like apt (Debian/Ubuntu), yum (CentOS), or pacman (Arch) are specific to certain Linux distributions. Verify compatibility with your system.
  • Advanced Chaining: The chaining examples here are simplified. Combine multiple commands for more complex tasks as you gain experience.
  • Documentation: Always consult man pages or online resources for detailed command options and advanced usage.
  • Safety First: Commands like rm, kill, or mkfs can cause data loss or system issues if misused. Double-check before executing.

Why This Cheat Sheet Rocks

This cheat sheet isn’t just a list—it’s a roadmap to Linux mastery. Each command comes with practical examples and chaining ideas to help you work smarter, not harder. Bookmark this page, share it with your fellow hackers, and revisit it whenever you need to conquer the terminal. Stay curious, keep experimenting, and happy hacking!

Originally published on SquidHacker – Your source for Linux tips, cybersecurity, and tech tutorials.