Linux Commands Cheat Sheet

crackr.dev

1Top 20 Commands

The commands you'll use 80% of the time

1.lsList files
2.cdChange directory
3.pwdPrint working directory
4.cpCopy files/dirs
5.mvMove or rename
6.rmRemove files/dirs
7.mkdirCreate directory
8.catPrint file contents
9.grepSearch text patterns
10.chmodChange permissions
11.sudoRun as root
12.sshRemote login
13.curlTransfer data / HTTP
14.psList processes
15.killTerminate process
16.tarArchive & compress
17.findSearch for files
18.dfDisk free space
19.echoPrint text / variables
20.manManual pages

2File Operations

View
ls -laList all + permissions
ls -lhSSort by size
tree -L 2Directory tree
Copy
cp file dstCopy file
cp -r dir/ dst/Copy directory
Move / Rename
mv old newRename file
mv file dir/Move to dir
Delete
rm fileDelete file
rm -rf dir/Delete directory
Create
mkdir -p a/b/cNested dirs
touch file.txtEmpty file
Link
ln -s target linkSymbolic link
readlink linkShow link target

3Search & Find

findby name/size/dategrepby contentlocateby index (fast)which

$find — Search by file attributes

find / -name '*.log'By filename pattern
find . -type f -size +100MFiles over 100MB
find . -mtime -7Modified in last 7 days
find . -type f -emptyEmpty files
find . -perm 777Files with 777 perms
find . -name '*.tmp' -deleteFind AND delete

$grep — Search inside files

grep 'text' fileBasic search
grep -rn 'text' .Recursive + line numbers
grep -i 'text' fileCase-insensitive
grep -v 'exclude'Lines NOT matching
grep -E 'a|b' fileRegex OR
grep -l 'text' *.pyOnly filenames

$Quick lookups

locate filenameFast indexed search
which cmdWhere is this binary?
whereis cmdBinary + man + source
type cmdHow shell resolves cmd

4Text Manipulation

Common pipeline pattern

cat file|grep err|sort|uniq -c|head

$Read & View

cat filePrint entire file
less fileScrollable viewer (q quit)
head -n 20 fileFirst 20 lines
tail -n 20 fileLast 20 lines
tail -f logfileFollow in real time

$Sort, Filter, Count

sort fileSort alphabetically
sort -n -r fileNumeric, reversed
uniqRemove adjacent dupes
sort | uniq -cCount occurrences
wc -l fileCount lines
wc -w fileCount words
cut -d',' -f1,3Extract CSV columns
tr 'A-Z' 'a-z'Lowercase

$sed — Stream editor

sed 's/old/new/g' fReplace all occurrences
sed -i 's/old/new/g' fIn-place edit
sed -n '5,10p' fPrint lines 5–10
sed '/^$/d' fDelete empty lines

$awk — Column processor

awk '{print $1, $3}'Print columns 1 and 3
awk -F: '{print $1}'Custom delimiter
awk '$3>100'Filter by value
awk '{s+=$1} END{print s}'Sum column
awk 'NR==5,NR==10'Print lines 5-10

5Network Commands

localcurlrequestDNSdigremotessh

$HTTP & Downloads

curl urlFetch content
curl -I urlHeaders only
curl -o file urlDownload to file
curl -X POST -d 'data' urlPOST request
wget urlDownload file
wget -q -O - urlDownload to stdout

$DNS & Connectivity

ping -c 4 hostTest reachability
traceroute hostTrace route
dig domainDNS lookup
nslookup domainDNS query
curl ifconfig.meYour public IP

$SSH & Transfer

ssh user@hostRemote login
ssh -i key user@hostLogin with key
scp file user@h:/pathCopy to remote
rsync -avz src/ h:dst/Sync efficiently

$Ports & Sockets

ss -tulnpListening ports + PIDs
lsof -i :8080What's on port 8080
ip addrShow IP addresses
ip routeShow routing table

6Process & System

terminal

$ 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 processes
ps aux | grep nameFilter by name
topLive monitor
htopBetter monitor (install)
pgrep -f nameGet PID by name

$Kill & Signal

kill PID

TERM (15)

Graceful

kill -9 PID

KILL (9)

Force

kill -1 PID

HUP (1)

Reload

killall nameKill all by name
pkill -f patternKill by pattern

$Background Jobs

cmd &Run in background
nohup cmd &Survive logout
jobsList background jobs
fg %1Bring to foreground
bg %1Resume in background

$System Info

uname -aKernel info
uptimeUptime + load
free -hMemory usage
lscpuCPU info
hostnameMachine name
dateDate & time

7Permission Commands

-rwxr-xr--= 754
chmod 755 filerwxr-xr-x (scripts, dirs)
chmod 644 filerw-r--r-- (regular files)
chmod 600 filerw------- (secrets)
chmod +x fileAdd execute permission
chmod -R 755 dir/Recursive permission set

$Ownership

chown user fileChange owner
chown user:group fileChange owner + group
chown -R user dir/Recursive
chgrp group fileChange group only

$Sudo & Users

sudo cmdRun as root
sudo -u user cmdRun as another user
sudo -iRoot interactive shell
whoamiCurrent username
idUID, GID, groups

8Disk & Storage

$Space Usage

df -hFilesystem disk usage
du -sh *Size of each item here
du -sh /pathTotal size of path
du -h --max-depth=1 /Top-level dir sizes
ncdu /Interactive analyzer

$Devices

lsblkList block devices
fdisk -lDisk partitions
mount /dev/sdb1 /mntMount partition
umount /mntUnmount
blkidUUIDs + FS types

9Archive & Compress

tar syntax breakdown

tar-c-z-v-fout.tar.gzdir/
creategzipverbosefileoutputsource
tar -czf out.tar.gz dir/Create gzip archive
tar -xzf file.tar.gzExtract gzip archive
tar -xzf f.tar.gz -C /dstExtract to directory
tar -tzf file.tar.gzList contents only
tar -cjf out.tar.bz2 dir/Create bzip2 archive

$Other formats

gzip fileCompress
gunzip f.gzDecompress
zip -r o.zip dir/Create zip
unzip f.zipExtract zip

10Services & Cron

$systemctl — Service Control

systemctl start svcStart service
systemctl stop svcStop service
systemctl restart svcRestart service
systemctl status svcCheck status
systemctl enable svcStart on boot
systemctl disable svcDon't start on boot

$Logs

journalctl -u svcService logs
journalctl -fFollow all logs
dmesg | tailKernel messages
tail -f /var/log/syslogSystem log

$Cron Scheduling

*****min hr day mon dow
*/5 * * * *Every 5 min
0 * * * *Every hour
0 2 * * *Daily 2 AM
0 0 * * 0Weekly Sun
30 9 * * 1-5Weekdays 9:30

crontab -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 -9

Count files in dir

find . -type f | wc -l

Top 10 largest dirs

du -sh */ | sort -rh | head -10

Replace in all files

find . -name '*.py' -exec sed -i 's/old/new/g' {} +

Watch log for errors

tail -f /var/log/syslog | grep -i error

Disk hogs

du -h --max-depth=1 / 2>/dev/null | sort -rh | head

Empty all .log files

find . -name '*.log' -exec truncate -s 0 {} +

List open ports

ss -tulnp | grep LISTEN

Unique IPs from log

awk '{print $1}' access.log | sort -u | wc -l

12Shell Shortcuts

bash / zsh / most shells
Ctrl+CKill
Ctrl+ZSuspend
Ctrl+DExit/EOF
Ctrl+LClear
Ctrl+RHistory search
Ctrl+ALine start
Ctrl+ELine end
Ctrl+WDelete word
Ctrl+UDelete line
TabAutocomplete

$History Tricks

!!Repeat last command
sudo !!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_forward

Continue learning