Linux commands cheat sheet: basic commands with examples
By Pull This RepoPosted 7 min read
Short answer
The basic Linux commands most people need are ls, cd, pwd, cp, mv, rm, mkdir, cat, less, grep, find, chmod, sudo, ps, top, kill, df, du, ip, ping, curl, ssh, tar and apt. To list running processes, use ps aux for a snapshot, top or htop for a live view, and pgrep with a name to find one process ID.
This Linux commands cheat sheet groups about 40 basic commands, and the flags you use most with them, by the job you are trying to do: moving around, handling files, searching, permissions, processes, disk space, networking, packages and services. Each row has a real example. The flags were checked against the man pages on man7.org, and the apt commands against Ubuntu's apt manual, on 22 November 2026. They work the same in Ubuntu, Debian, Fedora and in Linux on Windows through WSL, apart from the package manager.
Swap the example names, such as file.txt, alex or a process ID like 4321, for your own.
What are the basic Linux commands for moving around?
These seven tell you where you are and take you somewhere else.
| Command | What it does | Example |
|---|---|---|
pwd | print the folder you are in | pwd |
ls | list files | ls |
ls -la | list all files, including hidden ones, in long format | ls -la ~/Downloads |
ls -lh | long format with sizes like 1K, 234M, 2G | ls -lh |
ls -ltr | sort by time, oldest first (-t newest first, -r reverses) | ls -ltr /var/log |
cd | change folder | cd ~/projects |
cd .. | go up one level | cd .. |
cd ~ or plain cd takes you home. In ls, -a shows entries starting with a dot, which is where config files hide.
How do you create, copy, move and delete files?
| Command | What it does | Example |
|---|---|---|
mkdir | make a folder | mkdir notes |
mkdir -p | make nested folders, no error if they exist | mkdir -p app/src/lib |
touch | create an empty file, or update its time | touch todo.txt |
cp | copy a file | cp a.txt b.txt |
cp -r | copy a folder and everything in it | cp -r site site-backup |
cp -i | ask before overwriting | cp -i a.txt b.txt |
mv | move or rename | mv old.txt new.txt |
rm | delete a file | rm old.txt |
rm -r | delete a folder and its contents | rm -r build |
rm -i | ask before every removal | rm -i *.log |
ln -s | make a symbolic link | ln -s /opt/app/bin/app ~/bin/app |
There is no recycle bin in the terminal. rm -rf (recursive, never prompt) deletes at once, so read the path twice before you press Enter.
How do you read files in the terminal?
| Command | What it does | Example |
|---|---|---|
cat | print a whole file | cat README.md |
cat -n | print it with line numbers | cat -n script.sh |
less | scroll through a long file (q quits) | less /var/log/syslog |
head -n 20 | first 20 lines | head -n 20 data.csv |
tail -n 50 | last 50 lines | tail -n 50 app.log |
tail -f | keep printing new lines as the file grows | tail -f app.log |
wc -l | count lines | wc -l data.csv |
How do you search for files and text?
find searches for files by name, type, age or size. grep searches inside files for text.
| Command | What it does | Example |
|---|---|---|
find -name | files whose name matches a pattern | find . -name "*.deb" |
find -iname | same, ignoring case | find ~ -iname "readme*" |
find -type d | only folders (f for regular files) | find . -type d -name node_modules |
find -mtime | changed a number of days ago (-7 means within the last week) | find /var/log -mtime -7 |
find -size | by size (+100M means over 100 MB) | find ~ -size +100M |
grep | lines that contain a word | grep error app.log |
grep -i | ignore case | grep -i warning app.log |
grep -n | show line numbers | grep -n TODO main.py |
grep -r | search every file under a folder | grep -r "API_KEY" . |
grep -v | lines that do not match | grep -v DEBUG app.log |
grep -c | count matching lines | grep -c 404 access.log |
You can chain them with a pipe: ls -la | grep conf lists only entries that mention "conf".
How do Linux file permissions work?
Each file has read, write and execute rights for its owner, its group and everyone else, and chmod changes them. The chmod manual accepts a symbolic mode such as u+x or an octal number of up to four digits.
| Command | What it does | Example |
|---|---|---|
chmod +x | make a script executable | chmod +x install.sh |
chmod 644 | owner reads and writes, others read | chmod 644 notes.txt |
chmod 755 | owner full rights, others read and run | chmod 755 deploy.sh |
chown | change owner and group | sudo chown alex:alex file.txt |
chown -R | change owner for a whole folder | sudo chown -R alex:alex /srv/app |
sudo | run one command as the administrator | sudo apt update |
./install.sh then runs the script from the current folder.
How do you list running processes in Linux?
Use ps aux for a snapshot, top or htop for a live view, and pgrep to find one process by name. This is the part of Linux most people search for, so here it is in detail.
# every process, BSD syntax, with user, %CPU and %MEM columns
ps aux
# every process, standard syntax
ps -ef
# the 10 heaviest processes by CPU
ps aux --sort=-%cpu | head -n 11
# a process tree
ps -ejH
# live view, refreshes every few seconds
top
# the process IDs and full names of anything called nginx
pgrep -a nginxThe ps manual lists ps -ef as the way to see every process "using standard syntax" and ps axu as the BSD-syntax way; ps aux is the same thing with the letters in a different order. The u option is what adds the user, %CPU and %MEM columns. --sort takes a key with - for descending order, so --sort=-%cpu puts the busiest first.
Inside top, press P to sort by CPU, M to sort by memory, k to kill a task by its ID and q to quit. htop, which its site describes as "an interactive process viewer", is a friendlier alternative when your distribution packages it. It is GPL-2.0 licensed and had 8,467 stars on GitHub on 22 November 2026, with version 3.5.3 as its latest release.
| Command | What it does | Example |
|---|---|---|
pgrep -l | process IDs and names that match | pgrep -l python |
pgrep -f | match against the full command line | pgrep -f "node server.js" |
pgrep -u | only processes owned by a user | pgrep -u alex |
kill | send TERM to a process ID | kill 4321 |
kill -9 | send KILL, which cannot be caught | kill -9 4321 |
kill -l | list signal names | kill -l |
pkill | signal processes by name (TERM by default) | pkill firefox |
The kill manual says TERM "should be used in preference to the KILL signal (number 9)", because a program can catch TERM and clean up first. Use -9 only when TERM does nothing.
How do you check disk space, memory and system info?
| Command | What it does | Example |
|---|---|---|
df -h | free space on each mounted drive, human readable | df -h |
df -T | also show the file system type | df -hT |
du -sh | total size of a folder | du -sh ~/Downloads |
du -d 1 -h | size of each folder one level down | du -d 1 -h ~ |
free -h | memory and swap in use | free -h |
uname -a | kernel and system details | uname -a |
uname -r | kernel release only | uname -r |
uptime -p | how long the machine has been up, in plain words | uptime -p |
What are the Linux networking commands?
| Command | What it does | Example |
|---|---|---|
ip address show | your network interfaces and IP addresses | ip address show |
ping -c 4 | send 4 test packets, then stop | ping -c 4 example.com |
ss -tulpn | listening TCP and UDP ports, as numbers, with processes | sudo ss -tulpn |
curl -L | fetch a URL and follow redirects | curl -L https://example.com |
curl -o | save to a file name you choose | curl -L -o page.html https://example.com |
curl -O | save using the remote file's name | curl -LO https://example.com/file.tar.gz |
ssh | log in to another machine | ssh alex@192.168.1.20 |
ssh -p | connect on another port | ssh -p 2222 alex@server |
scp -r | copy a folder over SSH (port flag is capital -P) | scp -r site alex@server:/srv/ |
rsync -avz | sync a folder, archive mode, compressed | rsync -avz site/ alex@server:/srv/site/ |
How do you compress and extract files?
tar handles .tar.gz archives. -c creates, -x extracts, -t lists, -z filters through gzip and -f names the file.
tar -czf backup.tar.gz notes/ # create
tar -tzf backup.tar.gz # list what is inside
tar -xzf backup.tar.gz # extract hereHow do you install software and manage services?
On Ubuntu and Debian, apt installs software; on Fedora the equivalent is dnf. systemctl and journalctl control background services on systemd distributions.
| Command | What it does | Example |
|---|---|---|
apt update | refresh the package lists | sudo apt update |
apt upgrade | install available upgrades | sudo apt upgrade |
apt install | install a package | sudo apt install git |
apt remove | remove it, keep its config | sudo apt remove git |
apt search | search available packages for matching terms | apt search image editor |
apt list --installed | what is installed | apt list --installed |
systemctl status | is a service running? | systemctl status ssh |
systemctl restart | restart a service | sudo systemctl restart nginx |
systemctl enable | start a service at boot | sudo systemctl enable docker |
journalctl -u | logs for one service | journalctl -u ssh |
journalctl -f | follow new log lines live | journalctl -f |
Downloaded a .deb instead? Our guide to installing a .deb file on Ubuntu covers sudo apt install ./file.deb.
What is the catch with cheat sheets?
They show the common flags, not every flag, and a few commands differ between systems. macOS uses BSD versions of tools such as ls, sed and ps, so some options behave differently there, and apt, systemctl and journalctl are not part of macOS at all. When a flag surprises you, man command is the final word. If you are new to the terminal because a GitHub project told you to open one, how to clone a GitHub repo is a good next step.
Pull it. Stash it.
Questions people ask
How do I list running processes in Linux?
Run ps aux for a snapshot of every process with its user, CPU and memory use, or ps -ef for the standard-syntax version. For a live, refreshing view use top, or htop if it is installed. To find the ID of one program, run pgrep -a followed by its name.
What is the difference between ps aux and ps -ef?
They show the same processes in two syntaxes. The ps manual lists ps -ef as the way to see every process using standard syntax and ps axu as the BSD-syntax way. The u option switches to a user-oriented format that includes %CPU and %MEM columns.
How do I stop a process that will not close?
Find its ID with pgrep -a name, then run kill followed by the ID. With no signal named, kill sends TERM, which lets the program clean up. If it ignores that, kill -9 sends KILL, which the kill manual warns cannot be caught, so the program gets no chance to clean up.
Do these Linux commands work on Mac and in WSL?
In WSL, yes: you get a real Linux distribution, so the commands and flags here apply. macOS shares most command names, but its versions come from BSD, so some flags differ. apt, systemctl and journalctl are Linux tools and are not part of macOS.
How do I see the manual for a Linux command?
Type man followed by the command name, for example man ls, and press q to quit. Most tools also print a short summary with --help. Every flag on this page was checked against the man pages on man7.org on 22 November 2026.
Sources
- 1man7.org Linux man pages: ls, cp, mv, rm, mkdir, touch, cat, head, tail, ln (read 2026-11-22)
- 2man7.org: grep(1) (read 2026-11-22)
- 3man7.org: find(1) (read 2026-11-22)
- 4man7.org: chmod(1) and chown(1) (read 2026-11-22)
- 5man7.org: ps(1) (read 2026-11-22)
- 6man7.org: top(1) (read 2026-11-22)
- 7man7.org: pgrep(1), pkill (read 2026-11-22)
- 8man7.org: kill(1) (read 2026-11-22)
- 9man7.org: df(1), du(1), free(1), uname(1), uptime(1) (read 2026-11-22)
- 10man7.org: ip-address(8) and ss(8) (read 2026-11-22)
- 11man7.org: ping(8) (read 2026-11-22)
- 12man7.org: curl(1) (read 2026-11-22)
- 13man7.org: ssh(1), scp(1), rsync(1) (read 2026-11-22)
- 14man7.org: tar(1) (read 2026-11-22)
- 15man7.org: systemctl(1) and journalctl(1) (read 2026-11-22)
- 16man7.org: wc(1) and sort(1) (read 2026-11-22)
- 17Ubuntu manpage: apt(8), Noble (read 2026-11-22)
- 18htop official site (read 2026-11-22)
- 19htop-dev/htop
More repos like this
Get tomorrow's repo in your feed
One free, open source repo a day as a short video, shown working, with the catch named. Pull it. Stash it.
