Tech

Linux Commands Cheat Sheet: Essential Commands With Examples

Suggested path: Performance Engineering · View path →

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 ls before rm, and --dry-run where 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

CommandWhat it doesExample
pwdPrint the folder you are inpwd
ls -laList files, including hidden ones, with detailsls -la ~/projects
cdChange foldercd ~/projects/blog
mkdirCreate a foldermkdir -p notes/2026/november
cpCopy a file or foldercp -r site site-backup
mvMove or renamemv draft.md post.md
rmDelete a file (permanent)rm old-notes.txt
findSearch for files by namefind . -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.txt prints a whole file. Use it on small files only.
  • less file.log lets you scroll through a large file. Press q to quit.
  • head -n 20 file.log shows the first 20 lines, and tail -f app.log follows a log as new lines arrive.
  • grep -rn "TODO" src/ searches every file under src/ and shows line numbers.
  • wc -l file.txt counts lines. It is useful for checking how much data you have.
  • nano notes.txt opens a simple editor. Press Ctrl+O to save and Ctrl+X to 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.sh makes a script runnable.
  • chmod 600 ~/.ssh/id_ed25519 restricts a private key so only you can read it. SSH will refuse to work if it is too open.
  • sudo apt update runs 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

CommandWhat it does
ps aux | grep nodeFind running processes by name
top or htopLive view of CPU and memory use
kill 12345Ask process 12345 to stop (use kill -9 only as a last resort)
df -hFree disk space per drive, in readable units
du -sh *Size of each item in the current folder
free -hMemory in use and available
uptimeHow long the system has been running, and its load

Networking basics

  • ping -c 4 example.com checks whether a host responds. Stop it after four packets.
  • ip addr shows your network interfaces and IP addresses.
  • ss -tlnp lists the ports your machine is listening on, which helps when a port is already in use.
  • curl -I https://example.com fetches only the response headers, a quick way to check status codes and caching.
  • ssh user@server connects 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.

  1. cat access.log | grep " 500 " | wc -l counts how many requests returned a 500 error.
  2. ls -la > listing.txt saves output to a file, replacing anything already there. Use >> to append instead.
  3. npm test && npm run build runs the build only if the tests pass.
  4. command 2>&1 | tee log.txt shows 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 update refreshes the list of available packages.
  • sudo apt install git installs a package. Check the name first with apt search.
  • sudo apt upgrade updates 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 sudo for 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 Tab to complete file names and reduce typos.

A practice path for the first week

  1. Create a test folder and practise mkdir, cd, ls -la and pwd until moving around feels automatic.
  2. Create three files, copy one, rename one and delete one, using only the terminal.
  3. Run grep on a folder of text files and count the matches with wc -l.
  4. Pick one process from top, find it with ps, and stop it safely with kill.
  5. 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.

  • #Linux
  • #Terminal
  • #Command Line

Latest updates

The four most recent posts across StackSignal.

All posts