Linux Commands Cheat Sheet: Copy-Paste Commands by Task (With Examples)

This Linux commands cheat sheet is built for the moment you’re staring at a terminal and need the right command now. Every command is grouped by task, explained in one plain-English line, and paired with a realistic example you can copy and adapt. It starts with the 20 commands you’ll use every day, then covers files, text, searching, permissions, processes, disks, networking, packages, and users, plus the two things most cheat sheets skip: how pipes and redirection actually work, and a calm danger zone for commands that can wipe data.

It’s written for students, people moving over from Windows (maybe you just set up a dual boot), junior admins, and anyone running a homelab. If you want a slower, step-by-step introduction first, start with our basic Linux commands walkthrough and come back here as your reference.

How to use this cheat sheet

Each table row follows the same format:

  • Command (with key flags): what you type. Flags are the letters after a dash, like -l or -h.
  • What it does: one line, no jargon.
  • Example: a realistic command. Swap in your own file names, users, and IP addresses.

What does a flag do? Flags change a command’s behavior. Most can be combined: ls -l -a -h and ls -lah do the same thing. Long flags use two dashes, like --help.

How to get help on any command

CommandWhat it doesExample
man commandOpens the full manual page. Press / to search, q to quit.man tar
command --helpPrints a shorter usage summary for most programs.ls --help
help builtinHelp for shell built-ins like cd, which have no man page of their own in bash.help cd
man -k keywordSearches manual page descriptions when you don’t know the command name.man -k compress
type commandTells you whether something is a built-in, alias, or program file.type ll
tldr commandCommunity-written, example-first summaries. Not installed by default; install a tldr client from your distro’s packages first.tldr tar
A Linux terminal showing the manual page for the ls command, with the synopsis, description and option list
A real manual page (this one is man ls): every command documents itself — press q to quit when you are done. (Screenshot: MichaelsTechTutorials / YouTube)

Which Linux does this cover?

The commands target bash, standard core utilities, and systemd on Ubuntu/Debian-family systems, which is what most beginners and homelab servers run. Most of them work the same on Fedora, Rocky Linux, Arch, Raspberry Pi OS, and WSL. Where a distro does things differently (package managers, the admin group, service names), the table says so.

One 2026-specific note: Ubuntu 25.10 and Ubuntu 26.04 LTS ship Rust reimplementations by default, uutils coreutils and sudo-rs. They’re designed to be compatible, and this sheet sticks to common, long-standing options, so the commands below behave as described for everyday use.

Windows switchers: In a Linux terminal, Ctrl+C stops the running command. It does not copy. Use Ctrl+Shift+C and Ctrl+Shift+V to copy and paste in most terminal apps.

Start here: the 20 commands you’ll use daily

If you learn nothing else, learn these.

CommandWhat it doesExample
pwdShows which folder you’re in right now.pwd
ls -lahLists files with details, hidden files, and readable sizes.ls -lah ~/Downloads
cdChanges folder. cd .. goes up one level, cd ~ goes home, cd - goes back.cd /etc
mkdir -pCreates a folder, including any missing parent folders.mkdir -p projects/site/images
cp -rCopies files, or whole folders with -r.cp -r photos/ photos-backup/
mvMoves or renames a file or folder.mv draft.txt final.txt
rmDeletes files permanently. There is no recycle bin.rm old-notes.txt
catPrints a whole file to the screen. Best for short files.cat /etc/os-release
lessScrolls through a long file. / searches, q quits.less ~/.bashrc
tail -fShows the end of a file and keeps watching for new lines.tail -f app.log
grep -iFinds lines containing text, ignoring upper/lower case.grep -i "error" app.log
findFinds files by name, size, type, or age.find ~ -name "*.pdf"
nanoOpens a beginner-friendly text editor. Ctrl+O saves, Ctrl+X exits.nano notes.txt
sudoRuns one command with administrator (root) rights.sudo nano /etc/hosts
chmodChanges who can read, write, or run a file.chmod +x backup.sh
df -hShows free space on every mounted drive.df -h
du -shShows how much space a folder uses.du -sh ~/Videos
topLive view of running programs, CPU, and memory. q quits.top
systemctl statusShows whether a service is running and its latest log lines.systemctl status ssh
manOpens the manual for any command.man grep

Navigation and files

CommandWhat it doesExample
pwdPrints the full path of the current folder.pwd
lsLists files in a folder.ls /var/log
ls -lLong list: permissions, owner, size, date.ls -l ~/Documents
ls -aIncludes hidden files (names starting with a dot).ls -a ~
ls -lhLong list with sizes in K, M, G.ls -lh ~/Downloads
ls -ltLong list sorted by newest first.ls -lt ~/Downloads
cd folderMoves into a folder.cd ~/projects
cd ..Moves up one level.cd ..
cd ~ or cdGoes to your home folder.cd ~
cd -Jumps back to the previous folder.cd -
mkdirCreates a folder.mkdir reports
mkdir -pCreates nested folders in one go.mkdir -p 2026/q4/invoices
touchCreates an empty file, or updates a file’s timestamp.touch todo.txt
cp source destCopies a file.cp config.yml config.yml.bak
cp -rCopies a folder and everything in it.cp -r website/ website-old/
cp -iAsks before overwriting an existing file.cp -i report.pdf ~/Desktop/
cp -aCopies a folder while keeping permissions and timestamps (good for backups).cp -a ~/docs /mnt/backup/
mv source destMoves or renames.mv IMG_1001.jpg beach.jpg
mv -iAsks before overwriting.mv -i notes.txt ~/Documents/
rm fileDeletes a file permanently.rm temp.log
rm -iAsks for confirmation on each file.rm -i *.log
rm -r folderDeletes a folder and its contents.rm -r old-project/
rm -IAsks once before deleting more than three files or deleting recursively.rm -rI old-project/
rmdirDeletes a folder only if it’s empty (a safe option).rmdir empty-folder
ln -s target linkCreates a shortcut (symbolic link).ln -s /mnt/nas/media ~/media
fileTells you what kind of file something really is.file download.bin
statShows detailed info: size, permissions, timestamps.stat report.pdf

Paths in one line: / is the root of the whole system, ~ is your home folder, . is the current folder, and .. is the folder above. A path starting with / is absolute; anything else is relative to where you are.

Viewing and editing text

CommandWhat it doesExample
cat filePrints a file.cat /etc/hostname
cat -n filePrints a file with line numbers.cat -n script.sh
less fileScrolls a long file. /word searches, n finds next, g top, G bottom, q quits.less /etc/ssh/sshd_config
head -n 20Shows the first 20 lines.head -n 20 data.csv
tail -n 50Shows the last 50 lines.tail -n 50 app.log
tail -fFollows a file as new lines are added. Ctrl+C stops.tail -f /var/log/nginx/access.log
wc -lCounts lines in a file.wc -l users.csv
nano fileSimple editor. Ctrl+O save, Ctrl+X exit, Ctrl+W search.nano ~/.bashrc
vim filePowerful editor. Press i to type, Esc then :wq to save and quit, :q! to quit without saving.vim config.yml
diff -u old newShows line-by-line differences between two files.diff -u config.bak config
sortSorts lines alphabetically. Add -n for numbers, -r to reverse.sort names.txt
uniq -cCollapses repeated adjacent lines and counts them (sort first).uniq -c sorted-ips.txt
cut -d, -f2Pulls out one column from delimited text.cut -d, -f2 data.csv
echoPrints text, or writes it to a file with >.echo "hello" > greeting.txt

Which editor should you use? Start with nano: the shortcuts are printed at the bottom of the screen (^ means Ctrl). Learn enough vim to exit it, because it’s the editor you’ll find on almost every server.

Searching: grep and find

grep searches inside files. find searches for files themselves.

CommandWhat it doesExample
grep "text" fileShows lines containing the text.grep "Listen" /etc/apache2/ports.conf
grep -iIgnores upper/lower case.grep -i "warning" app.log
grep -nShows line numbers.grep -n "TODO" main.py
grep -rSearches every file in a folder, recursively.grep -r "192.168.1.50" /etc
grep -rnRecursive search with line numbers (the combo you’ll use most).grep -rn "api_key" ~/projects
grep -vShows lines that do NOT match.grep -v "^#" /etc/fstab
grep -wMatches whole words only.grep -w "root" /etc/passwd
grep -cCounts matching lines.grep -c "Failed password" auth.log
grep -lLists only the names of files that match.grep -rl "localhost" ~/projects
grep -C 3Shows 3 lines of context before and after each match.grep -C 3 "panic" app.log
grep -EExtended patterns, such as “this OR that”.grep -E "error|fail" app.log
find path -nameFinds files by exact name pattern (case-sensitive).find ~ -name "*.mp4"
find path -inameSame, ignoring case.find ~/Pictures -iname "*.jpg"
find -type f / -type dLimits results to files or to directories.find ~/projects -type d -name "node_modules"
find -size +100MFinds files bigger than 100 MB.find ~ -type f -size +100M
find -mtime -1Finds files modified in the last 24 hours.find /var/log -type f -mtime -1
find -mmin -30Finds files modified in the last 30 minutes.find ~/projects -type f -mmin -30
find -emptyFinds empty files or folders.find ~/Downloads -type d -empty
whichShows the full path of a program you can run.which python3

Note on grep -E: in the table the pipe is shown escaped. In your terminal type it plainly: grep -E "error|fail" app.log

Tip: when find searches system folders as a normal user, it prints lots of “Permission denied” lines. Hide them with 2>/dev/null (explained in the pipes section below), or run it with sudo.

Permissions and ownership

Every file has an owner, a group, and three sets of permissions: for the owner (u), the group (g), and everyone else (o). Each set can include r (read), w (write), and x (execute, or “enter” for folders).

How do you read ls -l permissions? An example line looks like this:

-rwxr-xr-- 1 alice devs 2048 Oct 14 09:12 deploy.sh

The first character is the type (- file, d directory, l link). Then three groups of three: rwx for the owner (alice), r-x for the group (devs), and r-- for everyone else.

CommandWhat it doesExample
ls -lShows permissions, owner, and group.ls -l deploy.sh
chmod +xMakes a file executable (a script you can run).chmod +x deploy.sh
chmod u+xAdds execute for the owner only.chmod u+x deploy.sh
chmod go-wRemoves write permission from group and others.chmod go-w shared.txt
chmod o-rwxRemoves all access for “others”.chmod o-rwx payroll.csv
chmod 755Owner: everything. Everyone else: read and run.chmod 755 deploy.sh
chmod 644Owner: read/write. Everyone else: read only.chmod 644 index.html
chmod 600Owner only: read/write. Nobody else.chmod 600 ~/.ssh/id_ed25519
chmod -R u=rwX,go=rXFixes a whole folder safely: capital X adds execute only to folders and files that are already executable.chmod -R u=rwX,go=rX ~/shared
chown user:groupChanges owner and group (usually needs sudo).sudo chown alice:alice report.pdf
chown -RChanges ownership of a folder and everything inside it.sudo chown -R www-data:www-data /var/www/mysite
chgrpChanges just the group.sudo chgrp devs project.md
umaskShows the default permission mask applied to new files.umask

(www-data is the web server user on Debian and Ubuntu. Other distros use different names, such as nginx or apache.)

chmod numbers explained: 755, 644, 600

Each digit is the sum of read = 4, write = 2, execute = 1. The three digits are owner, group, others.

NumberLettersWho can do whatUse it for
755rwxr-xr-xOwner can do everything; everyone else can read and run/enter.Scripts, programs, and most folders
644rw-r--r--Owner can read and write; everyone else can only read.Regular files: web pages, configs, documents
600rw-------Only the owner can read and write.Private files: SSH private keys, files with passwords
700rwx------Only the owner can do anything.Private folders such as ~/.ssh

Why is chmod 777 a bad idea? It lets every user on the system change or replace the file. It’s almost never the right fix for a “permission denied” error. See the danger zone below.

Processes and services

Processes: see and stop running programs

CommandWhat it doesExample
ps auxLists every running process with its owner, CPU, and memory use.ps aux
pgrep -a nameFinds processes by name and shows their PID and full command.pgrep -a python3
topLive process view. Shift+P sorts by CPU, Shift+M by memory, q quits.top
htopA friendlier top with colors and mouse support. May need installing.htop
kill PIDAsks a process to stop politely (SIGTERM).kill 4821
kill -9 PIDForces a process to stop immediately (SIGKILL). Last resort; it can’t save its work.kill -9 4821
pkill nameStops processes by name.pkill firefox
pkill -f "text"Stops processes whose full command line matches.pkill -f "python3 app.py"
command &Runs a command in the background../long-job.sh &
jobsLists background jobs in this terminal.jobs
fg %1Brings job 1 back to the foreground.fg %1
bg %1Resumes a paused job in the background.bg %1
Ctrl+ZPauses the current foreground program.(press while a program runs)
nohup command &Keeps a command running after you log out; output goes to nohup.out.nohup ./backup.sh &

Services and logs: systemctl and journalctl

Most modern distros manage background services with systemd. systemctl controls services; journalctl reads their logs.

CommandWhat it doesExample
systemctl status nameShows if a service is running, plus recent log lines.systemctl status ssh
sudo systemctl start nameStarts a service now.sudo systemctl start ssh
sudo systemctl stop nameStops a service now.sudo systemctl stop ssh
sudo systemctl restart nameStops and starts a service (apply config changes).sudo systemctl restart ssh
sudo systemctl reload nameReloads config without a full restart (if the service supports it).sudo systemctl reload nginx
sudo systemctl enable --now nameStarts a service and sets it to start at every boot.sudo systemctl enable --now ssh
sudo systemctl disable nameStops a service from starting at boot.sudo systemctl disable bluetooth
systemctl is-active namePrints just “active” or “inactive”.systemctl is-active ssh
systemctl --failedLists services that failed.systemctl --failed
systemctl list-units --type=service --state=runningLists all running services.systemctl list-units --type=service --state=running
sudo systemctl daemon-reloadReloads unit files after you edit or add one.sudo systemctl daemon-reload
journalctl -u nameShows logs for one service.sudo journalctl -u ssh
journalctl -fFollows the system log live.sudo journalctl -f
journalctl -u name -fFollows one service’s log live.sudo journalctl -u ssh -f
journalctl -bShows logs from the current boot only.sudo journalctl -b
journalctl -b -1Shows logs from the previous boot (needs persistent journaling, the default on Ubuntu and Fedora).sudo journalctl -b -1
journalctl -p err -bShows only errors from this boot.sudo journalctl -p err -b
journalctl --sinceShows logs from a time window.sudo journalctl --since "1 hour ago"
journalctl -n 100Shows the last 100 log lines.sudo journalctl -u ssh -n 100

(The SSH service is called ssh on Ubuntu/Debian and sshd on Fedora and RHEL.)

Disk and system info

CommandWhat it doesExample
df -hFree and used space on every mounted filesystem.df -h
df -h /Free space on the drive holding a given path.df -h /home
df -iShows inode use (a disk can be “full” of tiny files even with free space).df -i
du -sh folderTotal size of one folder.du -sh /var/log
du -h --max-depth=1Size of each subfolder, one level deep.sudo du -h --max-depth=1 /var
free -hRAM and swap: total, used, available.free -h
uname -rKernel version.uname -r
uname -aKernel version, hostname, and architecture.uname -a
cat /etc/os-releaseWhich distro and version you’re running.cat /etc/os-release
hostnamectlHostname, OS, kernel, and hardware summary.hostnamectl
uptimeHow long the system has been up, plus load averages.uptime
lsblkLists disks and partitions as a tree.lsblk
lsblk -fAdds filesystem type, label, and UUID.lsblk -f
lscpuCPU model, cores, and threads.lscpu
nprocNumber of CPU threads available.nproc
dateCurrent date and time.date
timedatectlTime zone and clock sync status.timedatectl
sudo dmesgKernel messages (useful after plugging in hardware).sudo dmesg

Networking

CommandWhat it doesExample
ip aShows network interfaces and their IP addresses.ip a
ip -br aSame, in a compact one-line-per-interface view.ip -br a
ip routeShows the routing table, including your default gateway.ip route
hostname -IPrints just this machine’s IP addresses.hostname -I
ping -c 4 hostSends 4 test packets. Without -c, Linux pings forever (Ctrl+C stops).ping -c 4 1.1.1.1
ss -tulpnLists listening ports: TCP, UDP, with process names (needs sudo to see all processes).sudo ss -tulpn
curl -I URLFetches only a website’s HTTP headers (quick “is it up?” check).curl -I https://example.com
curl -L URLFetches a page and follows redirects.curl -L https://example.com
curl -O URLDownloads a file, keeping its original name.curl -O https://example.com/file.iso
curl -o name URLDownloads a file under a name you choose.curl -o ubuntu.iso https://example.com/file.iso
dig domainLooks up DNS records in detail.dig example.com
dig +short domainPrints just the IP address answer.dig +short example.com
dig @server domainAsks a specific DNS server.dig @1.1.1.1 example.com
nslookup domainSimpler DNS lookup, familiar from Windows.nslookup example.com
ssh user@hostLogs in to another machine securely.ssh [email protected]
ssh -p port user@hostSSH on a non-standard port.ssh -p 2222 [email protected]
scp file user@host:pathCopies a file to another machine over SSH.scp backup.tar.gz [email protected]:/home/alice/
rsync -avh src/ dest/Copies or syncs folders efficiently; re-runs only copy what changed.rsync -avh ~/photos/ [email protected]:/srv/photos/

(dig and nslookup come from a DNS utilities package that minimal installs may not include. On Ubuntu/Debian it’s bind9-dnsutils; on Fedora it’s bind-utils.)

What happened to ifconfig and netstat? They come from the old net-tools package, which many distros no longer install by default. ip and ss are the modern replacements. Running a homelab? sudo ss -tulpn is the fastest way to audit which services are exposed, and it’s a good first step in securing your homelab network.

Archives and packages

tar, zip, and gzip

tar flags decoded: c = create, x = extract, t = list, z = gzip, J = xz, v = verbose, f = the archive file name comes next.

CommandWhat it doesExample
tar -czf name.tar.gz folderCreates a gzip-compressed archive.tar -czf docs-backup.tar.gz ~/Documents
tar -xzf name.tar.gzExtracts a .tar.gz into the current folder.tar -xzf docs-backup.tar.gz
tar -xzf file -C folderExtracts into a specific (existing) folder.tar -xzf site.tar.gz -C /tmp/restore
tar -tzf name.tar.gzLists what’s inside without extracting.tar -tzf docs-backup.tar.gz
tar -xf archiveExtracts most tar formats; compression is detected automatically.tar -xf node-v22.tar.xz
tar -cJf name.tar.xz folderCreates a smaller (slower) xz-compressed archive.tar -cJf logs.tar.xz logs/
zip -r name.zip folderCreates a .zip (handy for sharing with Windows users).zip -r photos.zip photos/
unzip file.zipExtracts a .zip.unzip photos.zip
unzip -l file.zipLists a .zip’s contents.unzip -l photos.zip
gzip fileCompresses one file (replaces it with file.gz).gzip big.log
gunzip file.gzDecompresses a .gz file.gunzip big.log.gz

(zip and unzip may need installing on minimal systems.)

Installing software: package managers depend on your distro

There is no single universal Linux install command. Use the one your distro ships with. Not sure which you have? Run cat /etc/os-release.

TaskDebian / Ubuntu / Mint / Pop!_OS (apt)Fedora / RHEL / Rocky / Alma (dnf)
Refresh package listssudo apt updatesudo dnf check-update
Upgrade everythingsudo apt upgradesudo dnf upgrade
Install a packagesudo apt install htopsudo dnf install htop
Remove a packagesudo apt remove htopsudo dnf remove htop
Search for a packageapt search htopdnf search htop
Show package detailsapt show htopdnf info htop
Remove unused dependenciessudo apt autoremovesudo dnf autoremove

Arch-based distros use pacman, and openSUSE uses zypper. Many distros also support Flatpak or Snap for desktop apps. Stick to one package manager per task rather than mixing them for the same app.

Users and sudo basics

CommandWhat it doesExample
whoamiPrints your username.whoami
idShows your user ID and every group you belong to.id
groups userLists a user’s groups.groups alice
sudo commandRuns one command as root (asks for your password).sudo apt update
sudo !!Re-runs your previous command with sudo (bash).sudo !!
sudo -iOpens a root shell. Type exit to leave it.sudo -i
sudo -lLists what you’re allowed to run with sudo.sudo -l
su - userSwitches to another user’s login shell.su - bob
passwdChanges your own password.passwd
sudo passwd userSets another user’s password.sudo passwd bob
sudo adduser userCreates a user interactively (Debian/Ubuntu).sudo adduser bob
sudo useradd -m -s /bin/bash userCreates a user with a home folder (works on all distros).sudo useradd -m -s /bin/bash bob
sudo usermod -aG group userAdds a user to a group. Log out and back in for it to apply.sudo usermod -aG sudo bob
sudo userdel -r userDeletes a user and their home folder.sudo userdel -r bob
sudo visudoSafely edits sudo rules (checks syntax before saving).sudo visudo

(The admin group is sudo on Ubuntu/Debian and wheel on Fedora and RHEL.)

Pipes and redirection in plain English

This is the concept beginners miss most, and it’s what makes the command line powerful. Every command has input, normal output (stdout), and error output (stderr). These symbols redirect them:

Diagram of three terminal commands connected by pipes, with data flowing from one command to the next and finally into a file
Pipes chain commands together: each command’s output becomes the next one’s input, and redirection saves the result to a file. (Illustration: TheTechHow)
SymbolPlain English
| (pipe)“Send this command’s output into the next command.”
>“Save the output to a file, replacing whatever was in it.”
>>“Add the output to the end of a file.”
2>“Send error messages somewhere else.”
2>&1“Send errors to the same place as normal output.”
<“Read input from this file.”
&&“Run the next command only if this one succeeded.”
||“Run the next command only if this one failed.”

(In the table the pipe symbols are escaped for formatting. In the terminal you type a single | or ||.)

Real examples you’ll actually use:

# Pipe: find a process, sort folders by size, search your history
ps aux | grep -i firefox
du -sh * | sort -h
history | grep ssh

# Overwrite vs append
ls -l /etc > etc-listing.txt
echo "Backup finished at $(date)" >> ~/backup.log

# Hide "Permission denied" noise by sending errors to /dev/null
find / -name "nginx.conf" 2>/dev/null

# Save both output and errors from a script to one log file
./backup.sh > backup.log 2>&1

# Run the upgrade only if the update succeeded
sudo apt update && sudo apt upgrade

# Write to a root-owned file: "sudo echo ... > file" fails, tee works
echo "192.168.1.50  nas" | sudo tee -a /etc/hosts

Why does sudo echo "x" > /etc/file fail? The > is handled by your own shell before sudo runs, so the file is opened without root rights. Piping into sudo tee -a (append) or sudo tee (overwrite) fixes it.

Small gotcha: ps aux | grep firefox also lists the grep command itself. pgrep -a firefox gives a cleaner answer.

Keyboard shortcuts that save real time

These work in bash, the default shell on most distros.

ShortcutWhat it does
TabAuto-completes commands, file names, and paths. Press it constantly.
Tab TabShows all possible completions when there’s more than one.
Up / Down arrowsScrolls through previous commands.
Ctrl+RSearches your command history as you type. Press Ctrl+R again for older matches, Enter to run, Ctrl+G to cancel.
Ctrl+CStops the running command (it does not copy).
Ctrl+ZPauses the running command (fg resumes it).
Ctrl+DLogs out of the shell, or ends input.
Ctrl+LClears the screen (same as clear).
Ctrl+A / Ctrl+EJumps to the start / end of the line.
Ctrl+UDeletes from the cursor to the start of the line.
Ctrl+KDeletes from the cursor to the end of the line.
Ctrl+WDeletes the word before the cursor.
Alt+.Inserts the last argument of the previous command.
Ctrl+Shift+C / Ctrl+Shift+VCopy / paste in most terminal apps.

History commands:

CommandWhat it doesExample
historyLists your recent commands with numbers.history
!numberRe-runs command number N from history.!42
!!Re-runs the last command.!!

Windows to Linux: quick command translator

Coming from Command Prompt? These are the closest everyday equivalents.

Windows (cmd)LinuxNote
dirls -l
cdcd / pwdPlain cd on Linux goes home; use pwd to see where you are.
copy / xcopycp / cp -r
move / renmvOne command for both moving and renaming.
del / rmdir /srm / rm -rNo recycle bin.
typecat
clsclearOr Ctrl+L.
findstrgrep
wherewhich
ipconfigip a
pingping -c 4Linux keeps pinging until you press Ctrl+C.
tasklistps aux
taskkill /PIDkill
shutdown /r /t 0sudo reboot

Remember that Linux is case-sensitive: Report.txt and report.txt are two different files.

Danger zone: commands that can destroy data (and the safe habit for each)

Linux assumes you mean exactly what you type. There’s no “Are you sure?” and no recycle bin for terminal deletions. None of this is a reason to fear the terminal; it’s a reason to build a few habits.

Command or patternWhat can go wrongSafe habit
rm -rfDeletes folders permanently, with no prompt. A stray space is enough: rm -rf ~ /Downloads/old deletes your entire home folder and then /Downloads/old.Run ls on the exact path first. Use pwd to confirm where you are. Prefer rm -rI so you get one confirmation. Use tab completion instead of typing paths.
rm -rf "$DIR"/* in scriptsIf $DIR is empty, this becomes rm -rf /. Modern rm refuses rm -rf / by default, but that protection doesn’t cover /.Use rm -rf "${DIR:?}"/*, which stops the script with an error if the variable is empty.
chmod -R 777Makes every file writable by every user. On system paths it can break SSH logins and sudo, which refuse insecure permissions.Fix the specific file or folder. Use chmod -R u=rwX,go=rX folder, or add the user to the right group.
sudo chown -R on the wrong pathHands system files to the wrong user, breaking services.Check the path with ls -ld path first. Never run it on /, /etc, or /usr.
dd if=... of=/dev/sdXOverwrites the target disk completely. A wrong letter wipes the wrong drive.Run lsblk before and after plugging in the USB drive to confirm which device it is. Double-check the of= value. Device names can change between boots.
mkfsFormats a partition, erasing its filesystem.Confirm the device with lsblk -f (it shows existing filesystems and labels). Unmount it first.
> redirectcommand > file silently replaces the file’s contents.Use >> to append. Turn on protection with set -o noclobber (then > refuses to overwrite existing files; `>` forces it).
find ... -deleteDeletes every match instantly. Placed before the filters, it deletes everything under the path.Run the find without -delete first, check the list, then add -delete as the last option.
usermod -G group userWithout -a, it replaces the user’s groups, which can lock them out of sudo.Always use usermod -aG.
crontab -rDeletes all your scheduled jobs with no prompt. It’s one key away from crontab -e.Back up first: crontab -l > ~/crontab-backup.txt.
curl ... | sudo bashRuns a script from the internet as root before you’ve seen it.Download it, read it, then run it.
Firewall changes over SSHEnabling a firewall before allowing SSH locks you out of a remote server.On Ubuntu, run sudo ufw allow OpenSSH before sudo ufw enable. More in our homelab network security guide.

The one habit that matters most: have a backup. Every safe habit above reduces mistakes; only backups undo them.

When you need to… use…

When you need to…Use…
See which drive is fulldf -h
Find which folder is eating the spacesudo du -xh --max-depth=1 / then repeat on the biggest folder
Find files over 1 GBsudo find / -xdev -type f -size +1G
Fix “disk full” when du doesn’t add upsudo lsof +L1 (deleted files still held open; restart the program holding them)
Check how much space logs usejournalctl --disk-usage
Shrink the system journalsudo journalctl --vacuum-size=500M
See what’s listening on a portsudo ss -tulpn or sudo lsof -i :8080
Watch a log livesudo journalctl -u ssh -f or tail -f /var/log/nginx/error.log
Find out why a service failedsystemctl status name, then sudo journalctl -u name -b
See what’s using CPU or RAMtop (Shift+P for CPU, Shift+M for memory)
Stop a frozen programpkill name, and only if that fails, pkill -9 name
Find your IP addressip -br a or hostname -I
Tell a network problem from a DNS problemping -c 3 1.1.1.1 works but ping -c 3 example.com fails? It’s DNS.
Check which distro you’re oncat /etc/os-release
Find a command you ran last weekCtrl+R, then type part of it
Find text inside lots of filesgrep -rn "text" folder
Find where a program is installedwhich program
Extract a .tar.gztar -xzf file.tar.gz

(lsof is preinstalled on most desktop and server distros but may be missing from minimal images.)

Frequently asked questions

What are the most important Linux commands for beginners?

Start with pwd, ls, cd, mkdir, cp, mv, rm, cat, less, grep, find, nano, sudo, chmod, df, du, top, systemctl, and man. Those cover moving around, managing files, reading text, fixing permissions, and checking system health. Our basic Linux commands guide walks through them step by step.

Do these commands work on every Linux distro?

Almost all of them do, because they come from standard tools that ship everywhere. The main differences are package managers (apt on Debian/Ubuntu, dnf on Fedora/RHEL, pacman on Arch), the admin group (sudo vs wheel), and some service names (ssh vs sshd). Those differences are flagged in the tables.

Do Linux commands work on macOS or Windows?

On Windows, WSL (Windows Subsystem for Linux) runs a real Linux distribution, so these commands work there. macOS has a similar Unix terminal, but many of its built-in tools are BSD versions with different flags, and it doesn’t use systemctl, apt, or ip.

How do I undo rm in Linux?

Usually you can’t. Terminal deletions skip the trash, so restore from a backup. That’s why the danger zone recommends ls before rm, and rm -i or rm -I for prompts.

What’s the difference between > and >>?

> replaces a file’s contents with the command’s output. >> adds the output to the end of the file and keeps what was already there.

What does sudo do?

It runs a single command with administrator (root) privileges, after asking for your password. Use it only for commands that actually need it, such as installing software or editing system files.

How do I stop a command that’s running?

Press Ctrl+C. If a program is frozen in another window, find it with pgrep -a name and stop it with kill PID, or with kill -9 PID as a last resort.

Are ifconfig and netstat still used?

They still work where the net-tools package is installed, but many distros no longer include it by default. Use ip a instead of ifconfig and ss -tulpn instead of netstat.

How do I remember all these commands?

You don’t need to. Learn the 20 daily commands, lean on Tab completion and Ctrl+R history search, and check man or --help for flags. Keep this page (or the printable PDF) open for everything else.

Next steps

Bookmark this page as your Linux command line cheat sheet, and grab the printable PDF for your desk. If you’re still building the basics, our basic Linux commands walkthrough explains each core command in more depth. Setting up a server at home? Head to our homelab guide, then lock it down with how to secure a homelab network.

Similar Posts