Guides

Linux commands cheat sheet: files, processes, networking and more

The Linux commands a server admin uses daily (files, permissions, processes, networking, systemd, packages) in one reference, linking the full guide for each.

Published ~10 min read
On this page

Short answer: the tables below group the Linux commands a Linux VPS admin actually reaches for (files, processes, networking, permissions, packages), with the one-line version of what each does. Where a command has its own in-depth article (a full cheat sheet, or a specific error it throws), the table links to it.

Files and directories

CommandWhat it does
ls -laList files, including hidden ones, with permissions and sizes
cd pathChange directory
pwdPrint the current directory
cp -r src dstCopy, recursively for a directory
mv src dstMove or rename
rm -rf pathDelete, recursively and without confirmation; there is no undo
mkdir -p a/b/cCreate a directory, and any missing parent directories
touch fileCreate an empty file, or update its modified time
ln -s target linkCreate a symbolic link
find /path -name '*.log'Search for files by name, recursively
df -hDisk space free, per mounted filesystem, in human-readable units
du -sh pathTotal size of a directory

For finding what is filling a disk rather than just how full it is, see checking disk usage on Linux.

Permissions and ownership

CommandWhat it does
chmod 755 fileSet exact permissions by octal mode
chmod +x fileAdd execute, leaving read/write as they were
chown user:group fileChange the owning user and group
ls -l fileShow a file's current mode and owner

The full reference (octal vs symbolic mode, recursive chmod without breaking directories, and why 777 is almost never the fix) is in the chmod command guide.

Processes

CommandWhat it does
ps auxList every running process
top / htopLive, updating view of CPU and memory per process
kill PIDAsk a process to stop (SIGTERM)
kill -9 PIDForce-kill a process (SIGKILL, no cleanup)
pkill nameKill by process name instead of PID
nohup cmd &Run a command that survives the terminal closing

What every column in ps aux actually means is in ps aux explained.

Networking

CommandWhat it does
ip -4 addr showShow IPv4 addresses on every interface
ip routeShow the routing table
ss -tlnpList listening TCP ports and the process on each
ping hostTest reachability and round-trip time
curl -I urlFetch just the HTTP headers of a URL
dig domainQuery DNS records for a domain
nc -zv host portTest whether a single TCP port is open

More on ss, lsof and the other ways to check what is listening in checking open ports on Linux.

Setting an address so it stops changing on reboot is covered in static IP addresses, and clearing a stale DNS answer in flushing the DNS cache.

Services and logs (systemd)

CommandWhat it does
systemctl status nameIs a service running, and its recent log lines
systemctl restart nameRestart a service
systemctl enable nameStart a service automatically on boot
journalctl -u name -fFollow a service's logs live
journalctl -xeJump to the end of the system log with extra context

Installing software

DistributionInstallUpdate everything
Debian · Ubuntusudo apt install namesudo apt update && sudo apt upgrade
RHEL · Rocky · Almasudo dnf install namesudo dnf upgrade
Alpinesudo apk add namesudo apk update && sudo apk upgrade

A command not found right after installing often means the shell has not reloaded its command path yet (hash -r fixes that), or the package installs under a different binary name than expected:

Text processing

CommandWhat it does
cat filePrint a file's contents
less filePage through a file (q to quit)
grep text fileSearch for text inside a file
grep -r text dirSearch recursively through a directory
tail -f fileFollow a file as new lines are written to it
wc -l fileCount lines in a file
sed 's/old/new/g' fileReplace text (stream editor)

Archives and transfers

CommandWhat it does
tar -czvf out.tar.gz dir/Create a compressed archive
tar -xzvf out.tar.gzExtract one
scp file user@host:/pathCopy a file to a remote server over SSH
rsync -av src/ user@host:/path/Sync a directory, only transferring what changed

For an interactive session instead of a one-shot copy, see the sftp command.

More tar flags and what each one does in extracting tar.gz files on Linux.

Docker

Containers, images, Compose and cleanup have grown into their own reference: the Docker commands cheat sheet.

The one command that stops everyone

Sooner or later something opens vim (a git commit, crontab -e, a minimal server image with no nano installed), and the hardest part is getting back out:

Esc then :wq saves and quits; :q! quits and discards changes. The full table of exit commands, and why vim gets stuck in the first place, is in how to exit vim.

SSH, the entry point to all of the above

Every command on this page assumes you can already get into the server. Start with generating an SSH key if you have not yet.

For the order to run these in on a brand-new server (create a user, lock down SSH, set up a firewall), see initial server setup.

Frequently asked

What is the most important Linux command for a beginner to learn first?

cd and ls (moving around and seeing what is there), followed by cat or less to read a file and sudo for anything that needs elevated permissions. Everything else builds on being able to navigate and read first.

How do I see what is using CPU or memory on a Linux server?

top or htop for a live, updating view; ps aux for a one-time snapshot. htop is easier to read but is not always preinstalled; apt install htop or dnf install htop adds it.

How do I find a file when I don't know which directory it's in?

find / -name 'filename' searches recursively from the root; locate filename is faster if the locate database is installed and up to date (updatedb refreshes it), but will not find anything created since the last update.

What is the difference between kill and kill -9?

kill PID sends SIGTERM, asking the process to shut down cleanly and save its state. kill -9 PID sends SIGKILL, which the process cannot ignore or clean up after; use it only once a plain kill has failed.

Related articles

All guides

Initial server setup: the first ten minutes on a new VPS

A repeatable checklist for a fresh Ubuntu or Debian server: non-root user, key-only SSH, firewall, automatic security updates, hostname, timezone and swap.

What is a VPS? Virtual private servers explained, and how to choose one

A VPS is a virtual machine you rent with its own OS, IP address and root access. How it works, VPS vs shared and dedicated, sizing, and the first steps.

curl: command not found? How to fix it on any Linux distribution

curl is simply not installed. Fix: sudo apt install curl on Debian and Ubuntu, apk add curl on Alpine, dnf install curl on RHEL. Plus sudo, Docker and PATH.

nohup command: keep a process running after you log out

nohup runs a command that ignores the hangup signal, so it keeps running after SSH drops: nohup.out, redirecting output, disown, checking and stopping it.

pwd command: print working directory, -L vs -P and $PWD

The pwd command prints the directory your shell is in. -L vs -P with symlinks, $PWD and $OLDPWD, cd -, and how a script finds its own directory.

mkdir command: create folders in Linux, with -p for parent folders and -m for permissions

The mkdir command creates folders in Linux: -p for nested paths, -m for permissions, brace expansion, and fixes for File exists and Permission denied.

wc command: count lines, words, bytes and files on Linux

The wc command counts lines, words and bytes: wc -l, -w, -c, -m, -L, totals, wc -l < file, counting files with find, and grep -c vs grep | wc -l.

How to rename a directory in Linux: the mv command for files and folders

How to rename a directory in Linux with mv: rename files and folders, move them into directories, -i, -n and -T, bulk renames, and fixes for mv errors.

cat command in Linux: view, combine and create files

The Linux cat command prints and joins files. cat -n, -b, -s and -A, creating files with > and a heredoc, the cat file > file trap, tac and big files.

Unix vs Linux: what is actually different, and what is not

Unix vs Linux: UNIX is a certified, trademarked OS family born at Bell Labs; Linux is a free Unix-like kernel. History, POSIX, licensing, comparison table.

Vim commands cheat sheet: search, find and replace, delete lines

Vim find and replace with :%s/old/new/g, search with / and n, delete lines with dd, ggdG or :g/pattern/d. A Vim commands cheat sheet with real output.

man command in Linux: how to read man pages, sections and man -k

How to use the man command and Linux man pages: reading and searching a page, sections 1, 5 and 8, man -k and apropos, and man pages on minimal Ubuntu.

Bash for loop: lists, ranges, files, lines and arrays, with real output

Bash for loop syntax with tested output: lists, {1..10} ranges and steps, C-style loops, files, lines with while read, arrays, break, continue, parallel.

ls command in Linux: read ls -l, show hidden files, sort by size and list only directories

ls command in Linux: read ls -l columns, show hidden files, sort by size or date, list only directories, and why scripts should not parse ls.

~/.bashrc explained: when bash reads it, what belongs in it and how to fix it

What ~/.bashrc is, when bash reads it (login, non-login and SSH shells), what belongs in it vs ~/.profile, how to reload it and how to fix a broken bashrc.

pushd, popd and dirs: use the directory stack in bash, zsh and Windows

How pushd, popd and dirs work in bash and zsh: jump with +N and -N, dirs -v, cd - vs pushd, quiet output, use in scripts, plus pushd in cmd and PowerShell.