Linux Commands Cheat Sheet: Essential Commands With Examples
Most daily Linux work uses fewer than twenty commands. Learn those first and look up the rest.
Key takeaways
- Most daily Linux work uses fewer than twenty commands. Learn those first and look up the rest.
- Every command has a safe way to test it. Use
lsbeforerm, and--dry-runwhere a tool offers it. - Pipes (
|) and redirection (>) turn small commands into real tools.
How to use this cheat sheet
This is a working reference, not a tutorial. Each section groups commands by the job you are trying to do, with one example you can copy into a terminal. Most examples are safe to run in an empty test folder. The ones that change or delete data are marked clearly.
If you are new to the terminal, start with the first two sections. Once they feel natural, the rest will make more sense in context. For a broader introduction to running local tools, see how to set up a local LLM on 8 GB of VRAM, which relies on many of the same commands.
Moving around files and folders
| Command | What it does | Example |
|---|---|---|
pwd | Print the folder you are in | pwd |
ls -la | List files, including hidden ones, with details | ls -la ~/projects |
cd | Change folder | cd ~/projects/blog |
mkdir | Create a folder | mkdir -p notes/2026/november |
cp | Copy a file or folder | cp -r site site-backup |
mv | Move or rename | mv draft.md post.md |
rm | Delete a file (permanent) | rm old-notes.txt |
find | Search for files by name | find . -name "*.html" |
There is no trash bin in the terminal. rm deletes permanently. Run ls on the same path first to confirm what you are about to remove.
Reading and editing text
Most configuration, logs and code are plain text. These commands let you read, search and change it without opening an editor.
cat file.txtprints a whole file. Use it on small files only.less file.loglets you scroll through a large file. Pressqto quit.head -n 20 file.logshows the first 20 lines, andtail -f app.logfollows a log as new lines arrive.grep -rn "TODO" src/searches every file undersrc/and shows line numbers.wc -l file.txtcounts lines. It is useful for checking how much data you have.nano notes.txtopens a simple editor. PressCtrl+Oto save andCtrl+Xto exit.
Permissions and ownership
Run ls -l and the first column shows who can read, write and run each file. For example, -rwxr-xr-- means the owner can read, write and execute, the group can read and execute, and everyone else can only read.
chmod +x deploy.shmakes a script runnable.chmod 600 ~/.ssh/id_ed25519restricts a private key so only you can read it. SSH will refuse to work if it is too open.sudo apt updateruns one command with administrator rights. Use it only for commands you understand.
Avoid chmod 777. It makes a file writable by everyone on the system. It is the most common shortcut people reach for after a permission error, and the least safe.
Processes, disk and system health
| Command | What it does |
|---|---|
ps aux | grep node | Find running processes by name |
top or htop | Live view of CPU and memory use |
kill 12345 | Ask process 12345 to stop (use kill -9 only as a last resort) |
df -h | Free disk space per drive, in readable units |
du -sh * | Size of each item in the current folder |
free -h | Memory in use and available |
uptime | How long the system has been running, and its load |
Networking basics
ping -c 4 example.comchecks whether a host responds. Stop it after four packets.ip addrshows your network interfaces and IP addresses.ss -tlnplists the ports your machine is listening on, which helps when a port is already in use.curl -I https://example.comfetches only the response headers, a quick way to check status codes and caching.ssh user@serverconnects to a remote machine.scp file.txt user@server:/home/user/copies a file to it.
Pipes and redirection
The real power of the terminal comes from combining commands. A pipe (|) sends the output of one command into the next.
cat access.log | grep " 500 " | wc -lcounts how many requests returned a 500 error.ls -la > listing.txtsaves output to a file, replacing anything already there. Use>>to append instead.npm test && npm run buildruns the build only if the tests pass.command 2>&1 | tee log.txtshows output on screen and saves it, including error messages.
Learn to read a pipeline from left to right: each step takes the previous output and does one job.
Installing software
On Debian and Ubuntu systems, use apt. On Fedora and Red Hat systems, use dnf. Always refresh the package list before installing.
sudo apt updaterefreshes the list of available packages.sudo apt install gitinstalls a package. Check the name first withapt search.sudo apt upgradeupdates everything already installed. Run it on a schedule, not only when something breaks.
Common mistakes to avoid
Never paste a command you do not understand from a random website into a root terminal. Many dangerous commands look harmless, and a single wrong path can delete an entire system.
- Typing the wrong path with
rm -rf. Double-check the path, and prefer moving files to a backup folder while you are unsure. - Using
sudofor everything. Files created with root rights are often owned by root, which breaks later work in your own folders. - Ignoring the error text. Most errors name the file or setting that caused them. Read the first line before searching the web.
- Forgetting tab completion. Press
Tabto complete file names and reduce typos.
A practice path for the first week
- Create a test folder and practise
mkdir,cd,ls -laandpwduntil moving around feels automatic. - Create three files, copy one, rename one and delete one, using only the terminal.
- Run
grepon a folder of text files and count the matches withwc -l. - Pick one process from
top, find it withps, and stop it safely withkill. - Write a short shell script that prints the date and your disk usage, then make it runnable with
chmod +x.
When a command behaves differently
The commands on this page work on most Linux distributions, but options can differ slightly between versions. When an example fails or looks different on your machine, run man command or command --help to see the options your version supports.
Bookmark this page and return to it when you need a reminder. The commands you use most will soon become automatic.
Running a Linux server in the cloud? These commands are what you will use over SSH. Start with the cloud computing and AWS guide to set one up safely.
Frequently asked questions
What are the most important Linux commands to learn first?
Start with pwd, ls, cd, mkdir, cp, mv, rm, cat, grep and chmod. Those cover moving around, reading files, searching text and fixing permissions, which is most daily work.
Is rm permanent in Linux?
Yes. rm deletes files without moving them to a trash folder. Run ls on the same path first and consider moving files to a backup folder while you are unsure.
What does chmod 777 do and why should I avoid it?
chmod 777 gives read, write and execute rights to every user on the system. It removes a useful safety boundary and is a common security mistake. Set the narrowest permission that works, such as 644 for files or 600 for private keys.
How do I see which commands a program accepts?
Run man followed by the command name, or the command followed by --help. The options can differ slightly between Linux versions, so check the output on your own machine.