Linux Commands

A comprehensive Linux commands cheatsheet

Linux Commands Cheat Sheet

CommandDetailExample
lsList files and directoriesls -la
treeDirectory structuretree /home/user
pwdCurrent directorypwd
cdChange directorycd Documents
touchCreate filetouch file.txt
mkdirCreate directorymkdir projects
rmdirRemove empty dirrmdir old_folder
cpCopy filescp a.txt b.txt
mvMove / renamemv old.txt new.txt
rmDelete filesrm file.txt
statFile detailsstat file.txt
fileDetect file typefile image.png
duDisk usagedu -sh folder/
dfDisk freedf -h
realpathAbsolute pathrealpath file.txt

File Permissions

CommandDetailExample
chmodChange permissionschmod 755 script.sh
chownChange ownerchown user:file.txt
chgrpChange groupchgrp developers file.txt
getfaclView ACL permissionsgetfacl file.txt
setfaclSet ACL permissionssetfacl -m u:john:rwx file.txt
umaskDefault permission settingsumask 022
ls -lView permissions in long formatls -l
idShow user & group IDsid username
groupsShow user groupsgroups username
statDetailed file permission infostat file.txt
installCopy file with ownership & permsinstall -m 755 app.sh /usr/bin/
setcapSet Linux capabilitiessetcap cap_net_bind_service=+ep app
getcapView file capabilitiesgetcap app
suSwitch usersu root
sudoExecute as superusersudo rm file.txt

Viewing and Editing Files

CommandDetailExample
catView filecat file.txt
lessPaginated viewless log.txt
moreBasic viewmore file.txt
headFirst lineshead -n 10 file.txt
tailLast linestail -n 20 file.txt
watchAuto refresh command outputwatch -n 1 ls
nanoCLI text editornano notes.txt
vimAdvanced CLI editorvim config.conf
viClassic Unix editorvi file.txt
tacView file in reverse ordertac file.txt
nlView file with line numbersnl file.txt
wcCount lines, words, characterswc -l file.txt
sortSort file contentsort names.txt
uniqRemove duplicate linesuniq data.txt
cutExtract columns from filecut -d: -f1 /etc/passwd
pasteMerge lines from filespaste a.txt b.txt
columnFormat output into columnscolumn -t file.txt
stringsExtract readable stringsstrings binaryfile

Text Processing

CommandDetailExample
grepPattern searchgrep "error" log.txt
egrepExtended regex grepegrep "error \
fgrepFixed string grepfgrep "ERROR[1]" log.txt
awkAdvanced text processingawk '{print $1}' file.txt
sedStream editorsed 's/foo/bar/g' file.txt
cutColumn cutcut -d: -f1 /etc/passwd
sortSort outputsort -u names.txt
uniqRemove duplicatesuniq -c data.txt
wcWord/line/char countwc -l file.txt
trTranslate/delete characterstr 'a-z' 'A-Z' < file.txt
xargsBuild args from stdincat files.txt \
columnAlign output in columnscolumn -t data.txt
pasteMerge lines from filespaste a.txt b.txt
nlNumber linesnl file.txt
joinJoin files on fieldjoin a.txt b.txt
foldLine wrap textfold -w 50 file.txt
revReverse linesrev file.txt
prPretty print textpr file.txt

System Information

CommandDetailExample
unameKernel / OS infouname -a
hostnamectlHost & OS detailshostnamectl
uptimeSystem running timeuptime
htopInteractive process monitorhtop
topProcess viewtop
psProcess statusps aux
freeRAM usagefree -h
vmstatMemory & CPU statsvmstat 1
iostatDisk I/O statsiostat
lsblkBlock deviceslsblk -f
blkidBlock device UUIDsblkid
mountMount diskmount /dev/sdb1 /mnt
umountUnmount diskumount /mnt
dfDisk freedf -h
duDisk usagedu -sh /var/log
watchAuto-refresh command outputwatch free -h
dmesgKernel messagesdmesg \
uptimeLoad averageuptime
whoamiCurrent userwhoami
archSystem architecturearch
lscpuCPU informationlscpu
lsmemMemory infolsmem

Process Management

CommandDetailExample
psProcess listps aux
killKill process by PIDkill -9 1234
killallKill process by namekillall firefox
pkillKill by patternpkill -f python
bgResume job in backgroundbg %1
fgBring job to foregroundfg %1
jobsList background jobsjobs -l
niceStart process with prioritynice -n 10 python app.py
reniceChange running process priorityrenice -5 -p 1234
topReal-time process viewertop
htopInteractive process viewerhtop
watchRe-run command repeatedlywatch ps aux
straceSystem call tracingstrace ls
ltraceLibrary call tracingltrace curl example.com
timeMeasure execution timetime ./script.sh
uptimeLoad average infouptime
tloadTerminal load monitortload
htop -pMonitor specific PIDhtop -p 1234
pstreeProcess tree viewpstree -p

Networking

CommandDetailExample
ipNetwork configurationip a
ifconfigLegacy interface toolifconfig eth0
iwconfigWireless configurationiwconfig wlan0
nmcliNetworkManager CLInmcli dev status
pingICMP connectivity testping google.com
tracerouteRoute tracingtraceroute google.com
tracepathLightweight route tracetracepath google.com
netstatNetwork statistics (legacy)netstat -tulnp
ssSocket statistics (modern)ss -tulnp
arpARP tablearp -a
ip neighNeighbor/ARP tableip neigh
routeLegacy routing tableroute -n
ip routeModern routing tableip route show
mtrPing + traceroute combomtr google.com
nmapNetwork scanningnmap -sV 192.168.1.1
tcpdumpPacket capturetcpdump -i eth0
tsharkCLI Wiresharktshark -i eth0
curlHTTP/network clientcurl -I https://example.com
wgetDownload over networkwget https://example.com/file.zip
nc / netcatNetwork debugging toolnc -lvnp 4444
whoisDomain/IP infowhois example.com
digDNS lookupdig example.com
nslookupDNS querynslookup example.com

DNS Tools

CommandDetailExample
digDNS lookupdig example.com
nslookupDNS querynslookup example.com
whoisDomain registration infowhois example.com
curlHTTP/HTTPS requestscurl -I https://example.com
wgetDownload fileswget https://example.com/file.zip
ftpFTP clientftp ftp.example.com
sftpSecure FTP over SSHsftp user@server
scpSecure copy over SSHscp file.txt user@server:/tmp/
rsyncEfficient file syncrsync -avz dir/ user@server:/backup/
sshSecure remote loginssh user@server
telnetPlain TCP client (legacy)telnet example.com 80
ncNetcat – read/write networknc -vz example.com 443
httpieUser-friendly HTTP clienthttp GET https://example.com
aria2cAdvanced downloaderaria2c https://example.com/file.iso
lynxCLI web browserlynx https://example.com
opensslTLS / cert inspectionopenssl s_client -connect example.com:443
timeoutLimit command execution timetimeout 5 curl example.com

Package Management

CommandDetailExample
aptDebian package managerapt update
apt-getInstall/remove packagesapt-get install nginx
apt-cacheSearch & inspect packagesapt-cache search python3
apt-keyManage APT keys (legacy)apt-key list
dpkgManage .deb packagesdpkg -i app.deb
dpkg-queryQuery installed packagesdpkg-query -l
add-apt-repositoryAdd PPA repositoriesadd-apt-repository ppa:deadsnakes/ppa
snapSnap package managersnap install code
snapctlControl snap servicessnapctl services
flatpakFlatpak package managerflatpak install flathub org.gimp.GIMP
pipPython package installerpip install requests
pip3Python3 package installerpip3 install flask
pipxInstall Python CLI tools safelypipx install httpie
gemRuby package managergem install bundler
npmNode.js package managernpm install express
npxRun npm packages without installnpx create-react-app app
yarnAlternative Node package manageryarn add react
brewmacOS/Linuxbrew package managerbrew install wget
condaPython data-science packagesconda install numpy

User Management

CommandDetailExample
useraddAdd new useruseradd alice
usermodModify user accountusermod -aG sudo alice
userdelDelete useruserdel -r alice
passwdChange user passwordpasswd alice
suSwitch usersu - root
sudoExecute as superusersudo apt update
loginLogin to systemlogin alice
logoutLogout from sessionlogout
exitExit shell/sessionexit
groupsShow user groupsgroups alice
idShow user & group IDsid alice
groupaddAdd groupgroupadd developers
groupmodModify groupgroupmod -n dev developers
groupdelDelete groupgroupdel developers
newgrpSwitch primary groupnewgrp developers
whoamiCurrent userwhoami
whoLogged-in userswho
wUser activity & loadw
lastLogin historylast
lastlogLast login per userlastlog
faillogFailed login attemptsfaillog -a

Security & Penetration Testing

Command / ToolDetailExample
nmapNetwork & port scannernmap -sV -p- target.com
masscanUltra-fast port scannermasscan target.com -p1-65535 --rate 1e5
netdiscoverLAN host discoverynetdiscover -r 192.168.1.0/24
amassSubdomain enumerationamass enum -d example.com
subfinderPassive subdomain discoverysubfinder -d example.com
dnsenumDNS enumerationdnsenum example.com
whatwebWeb technology fingerprintingwhatweb https://example.com
theHarvesterOSINT (emails, hosts)theHarvester -d example.com -b all
httpxHTTP probing & tech detectionhttpx -l subs.txt -title -status-code
naabuFast port discoverynaabu -host example.com
assetfinderFind related domainsassetfinder example.com
waybackurlsArchived URLs (Wayback)waybackurls example.com
gauGet all URLs (GAU)gau example.com
hakrawlerCrawl URLshakrawler -u https://example.com
ffufFuzzing (dirs, params)ffuf -u https://site/FUZZ -w wordlist
dirsearchDirectory brute-forcedirsearch -u https://example.com
niktoWeb server scannernikto -h https://example.com
wafw00fWAF detectionwafw00f https://example.com
sslscanSSL/TLS analysissslscan example.com

Web Application Testing

Command / ToolDetailExample
niktoWeb vulnerability scannernikto -h https://example.com
sqlmapSQL injection testingsqlmap -u "http://site/page?id=1"
wpscanWordPress security scannerwpscan --url https://site.com
msfconsoleMetasploit frameworkmsfconsole
searchsploitExploit-DB searchsearchsploit apache 2.4
hydraOnline brute-force attackshydra -l admin -P pass.txt ssh://target
medusaParallel auth brute-forcermedusa -h target -u admin -P pass.txt -M ssh
crackmapexecActive Directory attackscrackmapexec smb 10.0.0.0/24
nucleiTemplate-based vuln scannernuclei -u https://example.com
burpsuiteWeb proxy & testingburpsuite
zaproxy (ZAP)OWASP web scannerzaproxy
johnPassword crackerjohn hashes.txt
hashcatGPU password crackinghashcat -m 0 hashes.txt wordlist.txt
enum4linuxSMB enumerationenum4linux target
rpcclientRPC enumerationrpcclient -U "" target
responderLLMNR/NBT-NS poisoningresponder -I eth0
evil-winrmWinRM shellevil-winrm -i target -u user -p pass
impacket-*AD & network attack scriptsimpacket-smbclient user@target
xsserXSS testingxsser -u https://site.com

Wireless Attacks

Command / ToolDetailExample (generic)
airmon-ngEnable monitor modeairmon-ng start wlan0
airodump-ngCapture wireless packetsairodump-ng wlan0mon
aireplay-ngInjection / deauth testingaireplay-ng --test wlan0mon
aircrack-ngCrack captured handshakesaircrack-ng capture.cap
iwModern wireless configurationiw dev
iwconfigLegacy wireless configiwconfig
washWPS detection & scanwash -i wlan0mon
reaverWPS PIN attack (legacy)reaver -i wlan0mon
bettercapMITM & network frameworkbettercap -iface wlan0
hcxdumptoolCapture WPA handshakes/PMKIDhcxdumptool -i wlan0mon
hcxpcapngtoolConvert captures for crackinghcxpcapngtool capture.pcapng
kismetWireless sniffer & IDSkismet
mdk4Stress & testing toolmdk4 wlan0mon
wifiteAutomated Wi-Fi auditingwifite
macchangerChange MAC addressmacchanger -r wlan0
rfkillEnable/disable wireless radiosrfkill list
nmcliNetworkManager (Wi-Fi control)nmcli dev wifi list

Cryptography & Hashing

Command / ToolDetailExample
hashcatAdvanced hash crackinghashcat -m 0 hashes.txt wordlist.txt
johnPassword crackerjohn hashes.txt
opensslCryptography & SSL toolkitopenssl enc -aes-256-cbc -in a.txt
gpgFile & email encryptiongpg -c secret.txt
base64Encode / decode database64 file.txt
md5sumMD5 hashmd5sum file.txt
sha1sumSHA-1 hashsha1sum file.txt
sha256sumSHA-256 hashsha256sum file.txt
sha512sumSHA-512 hashsha512sum file.txt
bcryptPassword hashing (strong)htpasswd -nbB user pass
argon2Modern password hashingargon2 pass -id -t 3 -m 16
htpasswdCreate password hasheshtpasswd -n user
zipPassword-protect archiveszip -e secure.zip file.txt
7zEncrypted archives7z a secure.7z file.txt
xxdHex dump / reversexxd file.bin
stringsExtract readable stringsstrings binary
fileDetect file typefile hash.txt

Binary Analysis & Reverse Engineering

Command / ToolDetailExample
stringsExtract readable textstrings binary.exe
binwalkFirmware & file analysisbinwalk firmware.bin
objdumpDisassemble / inspect binariesobjdump -d program
readelfELF binary analysisreadelf -h binary
hexdumpHexadecimal viewhexdump -C file.bin
xxdHex view & reversexxd file.bin
volatilityMemory forensics frameworkvolatility -f mem.raw imageinfo
fileDetect file typefile unknown.bin
statFile metadatastat file.bin
nmList symbols in binarynm program
lddShared library dependenciesldd program
straceSystem call tracestrace ./program
ltraceLibrary call traceltrace ./program
foremostFile carvingforemost image.dd
scalpelAdvanced file carvingscalpel disk.img
exiftoolMetadata extractionexiftool image.jpg
pdfinfoPDF metadatapdfinfo file.pdf
radare2Reverse engineering frameworkradare2 binary
ghidraGUI reverse engineering suiteghidraRun

Logging & Monitoring

CommandDetailExample
journalctlsystemd system logsjournalctl -xe
dmesgKernel ring buffer logsdmesg \
lastLogin historylast
lastlogLast login per userlastlog
whoCurrently logged-in userswho
wUser activity & loadw
whoamiCurrent userwhoami
faillogFailed login attemptsfaillog -a
journalctl -uLogs of specific servicejournalctl -u ssh
journalctl -fFollow logs (live)journalctl -f
tailView end of log filetail -f /var/log/syslog
lessPaginated log viewingless /var/log/auth.log
grepSearch inside logsgrep "error" /var/log/syslog
ausearchSearch audit logsausearch -m USER_LOGIN
auditctlConfigure audit rulesauditctl -l
aureportAudit summary reportsaureport -au
logrotateRotate & manage logslogrotate -f /etc/logrotate.conf
serviceCheck service status (legacy)service ssh status
systemctlManage & inspect servicessystemctl status ssh
uptimeSystem load & running timeuptime
psProcess snapshotps aux \
topLive process & resource monitortop
htopInteractive monitoringhtop

Scheduling & Job Management

CommandDetailExample
cronBackground job scheduler servicesystemctl status cron
crontabUser cron configurationcrontab -e
crontab -lList cron jobscrontab -l
atSchedule one-time jobecho "backup.sh" \
atqList scheduled at jobsatq
atrmRemove at jobatrm 2
watchRepeat command outputwatch -n 2 df -h
timeoutLimit command execution timetimeout 10 ping google.com
sleepDelay executionsleep 5
batchRun job when system load is lowecho "script.sh" \
systemctlManage cron & timer servicessystemctl list-timers
systemd-runRun command as systemd unitsystemd-run --on-active=5m backup.sh
anacronRun missed cron jobsanacron -T
fcronAdvanced cron alternativefcrontab -e
nohupRun job immune to hangupnohup longtask.sh &
bgResume job in backgroundbg %1
fgResume job in foregroundfg %1
jobsList background jobsjobs

Development & Programming

CommandDetailExample
gccCompile C programsgcc main.c -o app
g++Compile C++ programsg++ main.cpp -o app
makeBuild automation toolmake
cmakeCross-platform build systemcmake . && make
lddShow shared library dependenciesldd app
objdumpDisassemble / inspect binariesobjdump -d app
readelfELF binary analysisreadelf -a app
straceSystem call debuggingstrace ./app
ltraceLibrary call debuggingltrace ./app
gdbGNU debuggergdb ./app
valgrindMemory leak detectionvalgrind ./app
python3Python interpreterpython3 script.py
pip3Python package managerpip3 install flask
venvPython virtual environmentpython3 -m venv venv
nodeJavaScript runtimenode app.js
npmNode.js package managernpm install express
npxRun Node tools without installnpx vite
javaRun Java programsjava Main
javacCompile Java sourcejavac Main.java
mvnMaven build toolmvn package
gradleGradle build systemgradle build
goGo language toolchaingo run main.go
rustcRust compilerrustc main.rs
cargoRust package managercargo build
phpPHP interpreterphp index.php

Miscellaneous Tools

CommandDetailExample
historyCommand historyhistory \
clearClear terminal screenclear
resetReset terminal / ttyreset
scriptRecord terminal sessionscript session.log
scriptreplayReplay recorded sessionscriptreplay session.log
screenTerminal multiplexerscreen -S mysession
tmuxAdvanced terminal multiplexertmux new -s mysession
tmux attachAttach to existing sessiontmux attach -t mysession
proxychainsRoute traffic through proxyproxychains curl https://example.com
torsocksRoute app through Tortorsocks curl https://example.com
torTor daemon / networksystemctl start tor
wgetDownload via CLIwget https://example.com/file
curlHTTP requests via CLIcurl -I https://example.com
nc / netcatTCP/UDP connectivitync -lvnp 4444
sshSecure remote loginssh user@host
scpSecure copy over SSHscp file user@host:/path/
rsyncSync filesrsync -avz src/ user@host:/backup/
digDNS lookupdig example.com
nslookupDNS querynslookup example.com
whoamiCurrent userwhoami