Linux commands cheatsheet

Essential Linux and bash commands for files, permissions, processes, networking and packages (apt, dnf, pacman), searchable and one click to copy.

loading Linux commands cheatsheet
About this tool

What is a Linux command cheatsheet?

The Linux terminal has hundreds of commands, and most people use twenty of them. The rest you look up: how to find a file bigger than 100 MB, which flag makes tar extract, how to see which process holds a port. A cheatsheet is the short list you keep open next to the shell, with the command ready to copy, so you do not have to remember the order of -xzvf.

This one is organised by task. The fifteen sections cover navigation, files and directories, viewing and editing text, search, permissions and ownership, processes, system and disk, users and groups, network, archives, pipes and redirection, and then the package managers apt (Debian, Ubuntu), dnf (Fedora, RHEL) and pacman (Arch), and finally services with systemctl and logs with journalctl. Each item has a plain description and one to four commands.

Placeholders are written between angle brackets, such as <file>, <directory>, <user>, <host> and <port>. Replace them, brackets included, before you run anything. Some commands change or delete things for good, such as rm -r, kill -9, sed -i and userdel -r, and the descriptions warn about them. The page is plain reference material that runs in your browser, with no account and nothing sent anywhere. For file modes in depth, use the chmod calculator.

How to use the Linux cheatsheet

  1. Open the page and scroll, or use the section chips at the top to jump straight to a group such as Network or Processes.
  2. Type in the search box to filter. It looks at the description, the section title and the commands, and every word has to match, so port process finds the items about finding what uses a port. Capital letters and accents are ignored.
  3. Press / anywhere on the page to put the cursor in the search box without touching the mouse.
  4. Click the copy button next to a command to copy it. When an item has several commands, all of them are copied, one per line.
  5. Use the Copy section button in a section title to take every command of that group at once.
  6. Click Print to get a clean paper or PDF version of the sheet, without the buttons.
  7. Replace the placeholders in angle brackets, read the command once more, and paste it into your terminal.

When you need to see what a sed or diff changed, compare the two versions in the text diff.

Examples

Find out what is using a port

Item "Find which process uses a port". Suppose port 8080 is taken:

sudo ss -ltnp | grep :8080
LISTEN 0 511 0.0.0.0:8080 0.0.0.0:* users:(("node",pid=4121,fd=19))

The process is node with PID 4121. Ask it to stop with kill 4121. Only if it ignores you, use kill -9 4121, which gives it no chance to clean up.

Set the permissions of a script and a private key

chmod 755 deploy.sh
chmod 600 ~/.ssh/id_ed25519
ls -l deploy.sh
-rwxr-xr-x 1 ana ana 214 Nov 20 10:12 deploy.sh

755 gives the owner read, write and execute (7) and everybody else read and execute (5). The 600 on the private key is what SSH expects: only you can read it.

Search text inside a project

Item "Search in all files of a directory, ignoring case, with line numbers":

grep -rin "timeout" src/
src/client.js:42:  const TIMEOUT = 5000;
src/config.yml:7:timeout: 30

-r goes through subdirectories, -i ignores case and -n prints the line number.

Pack a folder and list it without extracting

tar -czvf backup.tar.gz projects/
tar -tzvf backup.tar.gz

The first command creates the archive, the second only lists what is inside. To extract, tar -xzvf backup.tar.gz, optionally with -C <directory> to choose the destination.

Common errors and how to fix them

  • Permission denied: your user cannot read, write or run that file. Check with ls -l. Fix the mode with chmod or the owner with chown. Use sudo only when the file really belongs to the system.
  • command not found: the program is not installed or is not in your PATH. Check with which <command>, and install it with apt, dnf or pacman, whichever your distribution uses.
  • rm -r removed the wrong thing: there is no trash and no undo. Run ls <directory> first with the exact same path, and never paste a path you did not read. Be extra careful with variables that may be empty.
  • sed -i broke the file: it edits in place. Run the command without -i first to see the result on screen, or make a copy with cp.
  • apt and dnf do not exist: package managers depend on the distribution. Use apt on Debian and Ubuntu, dnf on Fedora and RHEL, pacman on Arch. cat /etc/os-release tells you which one you have.
  • kill -9 as a first choice: SIGKILL cannot be caught, so the program loses unsaved data and leaves temporary files. Try plain kill <pid> and wait a few seconds.
  • No command matches your search: remove a word. All words must match at once.

Frequently asked questions

How do I find a file by name in Linux?

Use find <directory> -name "*.log". The pattern goes in quotes so the shell does not expand it first. For text inside files, use grep -rin "text" <directory>.

What does chmod 755 mean?

Three digits for the owner, the group and everybody else. Read is 4, write is 2, execute is 1, and the digits add up. 7 is read, write and execute; 5 is read and execute. The chmod calculator shows the result as you click.

What is the difference between kill and kill -9?

kill sends SIGTERM, a polite request that the program can handle to close files and exit cleanly. kill -9 sends SIGKILL, which the kernel applies immediately and the program cannot intercept. Use it only when the process is stuck.

What is the difference between > and >>?

> overwrites the file with the output of the command. >> adds to the end of the file. Using > on an existing file erases what was there.

Does the cheatsheet run the commands?

No. It only shows and copies text. Nothing is executed, saved or sent; the commands run when you paste them in your own terminal.

Report a problem