pull/this/repo
RoundupGit, GitHub and developer tools#linux#terminal#how-to

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.

RoundupLinux commands cheat sheet: basic commands with examples

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.

CommandWhat it doesExample
pwdprint the folder you are inpwd
lslist filesls
ls -lalist all files, including hidden ones, in long formatls -la ~/Downloads
ls -lhlong format with sizes like 1K, 234M, 2Gls -lh
ls -ltrsort by time, oldest first (-t newest first, -r reverses)ls -ltr /var/log
cdchange foldercd ~/projects
cd ..go up one levelcd ..

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?

CommandWhat it doesExample
mkdirmake a foldermkdir notes
mkdir -pmake nested folders, no error if they existmkdir -p app/src/lib
touchcreate an empty file, or update its timetouch todo.txt
cpcopy a filecp a.txt b.txt
cp -rcopy a folder and everything in itcp -r site site-backup
cp -iask before overwritingcp -i a.txt b.txt
mvmove or renamemv old.txt new.txt
rmdelete a filerm old.txt
rm -rdelete a folder and its contentsrm -r build
rm -iask before every removalrm -i *.log
ln -smake a symbolic linkln -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?

CommandWhat it doesExample
catprint a whole filecat README.md
cat -nprint it with line numberscat -n script.sh
lessscroll through a long file (q quits)less /var/log/syslog
head -n 20first 20 lineshead -n 20 data.csv
tail -n 50last 50 linestail -n 50 app.log
tail -fkeep printing new lines as the file growstail -f app.log
wc -lcount lineswc -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.

CommandWhat it doesExample
find -namefiles whose name matches a patternfind . -name "*.deb"
find -inamesame, ignoring casefind ~ -iname "readme*"
find -type donly folders (f for regular files)find . -type d -name node_modules
find -mtimechanged a number of days ago (-7 means within the last week)find /var/log -mtime -7
find -sizeby size (+100M means over 100 MB)find ~ -size +100M
greplines that contain a wordgrep error app.log
grep -iignore casegrep -i warning app.log
grep -nshow line numbersgrep -n TODO main.py
grep -rsearch every file under a foldergrep -r "API_KEY" .
grep -vlines that do not matchgrep -v DEBUG app.log
grep -ccount matching linesgrep -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.

CommandWhat it doesExample
chmod +xmake a script executablechmod +x install.sh
chmod 644owner reads and writes, others readchmod 644 notes.txt
chmod 755owner full rights, others read and runchmod 755 deploy.sh
chownchange owner and groupsudo chown alex:alex file.txt
chown -Rchange owner for a whole foldersudo chown -R alex:alex /srv/app
sudorun one command as the administratorsudo 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.

terminal
# 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 nginx

The 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.

CommandWhat it doesExample
pgrep -lprocess IDs and names that matchpgrep -l python
pgrep -fmatch against the full command linepgrep -f "node server.js"
pgrep -uonly processes owned by a userpgrep -u alex
killsend TERM to a process IDkill 4321
kill -9send KILL, which cannot be caughtkill -9 4321
kill -llist signal nameskill -l
pkillsignal 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?

CommandWhat it doesExample
df -hfree space on each mounted drive, human readabledf -h
df -Talso show the file system typedf -hT
du -shtotal size of a folderdu -sh ~/Downloads
du -d 1 -hsize of each folder one level downdu -d 1 -h ~
free -hmemory and swap in usefree -h
uname -akernel and system detailsuname -a
uname -rkernel release onlyuname -r
uptime -phow long the machine has been up, in plain wordsuptime -p

What are the Linux networking commands?

CommandWhat it doesExample
ip address showyour network interfaces and IP addressesip address show
ping -c 4send 4 test packets, then stopping -c 4 example.com
ss -tulpnlistening TCP and UDP ports, as numbers, with processessudo ss -tulpn
curl -Lfetch a URL and follow redirectscurl -L https://example.com
curl -osave to a file name you choosecurl -L -o page.html https://example.com
curl -Osave using the remote file's namecurl -LO https://example.com/file.tar.gz
sshlog in to another machinessh alex@192.168.1.20
ssh -pconnect on another portssh -p 2222 alex@server
scp -rcopy a folder over SSH (port flag is capital -P)scp -r site alex@server:/srv/
rsync -avzsync a folder, archive mode, compressedrsync -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.

terminal
tar -czf backup.tar.gz notes/     # create
tar -tzf backup.tar.gz            # list what is inside
tar -xzf backup.tar.gz            # extract here

How 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.

CommandWhat it doesExample
apt updaterefresh the package listssudo apt update
apt upgradeinstall available upgradessudo apt upgrade
apt installinstall a packagesudo apt install git
apt removeremove it, keep its configsudo apt remove git
apt searchsearch available packages for matching termsapt search image editor
apt list --installedwhat is installedapt list --installed
systemctl statusis a service running?systemctl status ssh
systemctl restartrestart a servicesudo systemctl restart nginx
systemctl enablestart a service at bootsudo systemctl enable docker
journalctl -ulogs for one servicejournalctl -u ssh
journalctl -ffollow new log lines livejournalctl -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

  1. 1man7.org Linux man pages: ls, cp, mv, rm, mkdir, touch, cat, head, tail, ln (read 2026-11-22)
  2. 2man7.org: grep(1) (read 2026-11-22)
  3. 3man7.org: find(1) (read 2026-11-22)
  4. 4man7.org: chmod(1) and chown(1) (read 2026-11-22)
  5. 5man7.org: ps(1) (read 2026-11-22)
  6. 6man7.org: top(1) (read 2026-11-22)
  7. 7man7.org: pgrep(1), pkill (read 2026-11-22)
  8. 8man7.org: kill(1) (read 2026-11-22)
  9. 9man7.org: df(1), du(1), free(1), uname(1), uptime(1) (read 2026-11-22)
  10. 10man7.org: ip-address(8) and ss(8) (read 2026-11-22)
  11. 11man7.org: ping(8) (read 2026-11-22)
  12. 12man7.org: curl(1) (read 2026-11-22)
  13. 13man7.org: ssh(1), scp(1), rsync(1) (read 2026-11-22)
  14. 14man7.org: tar(1) (read 2026-11-22)
  15. 15man7.org: systemctl(1) and journalctl(1) (read 2026-11-22)
  16. 16man7.org: wc(1) and sort(1) (read 2026-11-22)
  17. 17Ubuntu manpage: apt(8), Noble (read 2026-11-22)
  18. 18htop official site (read 2026-11-22)
  19. 19htop-dev/htop

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.