Linux commands cheatsheet
The everyday commands, in one place
Files
ls [options] [path…]- ls lists the files and folders inside a directory.
cd [path]- cd (change directory) moves you into another folder.
pwd- pwd (print working directory) prints the full path of the folder you are currently in.
mkdir [-p] folder…- mkdir creates new folders (directories).
touch file…- touch creates an empty file if it does not exist, or updates the last-modified time of an existing file.
cp [options] source… destination- cp copies files and folders.
mv [options] source… destination- mv moves files and folders to another place, and is also how you rename them in Linux.
rm [options] file…- rm permanently deletes files.
tar [options] archive [files]- tar packs many files into one archive (.tar), usually compressed (.tar.gz).
Text
cat [options] file…- cat prints the whole content of one or more files to the screen.
less file- less opens a file in a scrollable viewer so you can read big files page by page and search inside them with /word.
head [-n N] file- head shows the first lines of a file — 10 by default, or any number with -n.
tail [-n N] [-f] file- tail shows the last lines of a file (10 by default).
wc [-lwc] [file]- wc (word count) counts lines, words and bytes.
sort [options] [file]- sort puts lines in order — alphabetically by default, numerically with -n, reversed with -r.
uniq [-c] [-d] [file]- uniq removes repeated lines that are next to each other; with -c it counts them.
cut -d DELIM -f FIELDS [file]- cut takes columns out of each line, split by a delimiter (-d) and choosing fields (-f).
awk [-F delim] 'program' [file]- awk processes text column by column.
sed [-i] 's/find/replace/g' [file]- sed is a stream editor: most often used to find and replace text, e.g.
tr SET1 SET2- tr translates or deletes characters — e.g.
Search
grep [options] pattern [file…]- grep searches text and prints only the lines that match a word or regular expression.
find [path] [tests] [actions]- find searches the file system for files by name, type, size, time, owner or permissions, and can run a command on each result.
Permissions
chmod [mode] file…- chmod changes who can read (r=4), write (w=2) and execute (x=1) a file, for the owner, the group and everyone else.
chown [-R] user[:group] file…- chown changes the owner (and optionally the group) of files and folders.
sudo [options] command- sudo runs a single command with administrator (root) rights, after checking that your user is allowed to in the sudoers rules.
System
whoami- whoami prints the user name you are currently running as.
id [user]- id shows your user id (uid), group id (gid) and every group you belong to.
df [-h]- df shows how much disk space is used and free on each mounted file system.
du [-sh] [path]- du shows how much space files and folders take.
free [-h]- free shows how much RAM and swap memory is used and available.
uname [-a]- uname prints system information — with -a it shows the kernel name, version and architecture.
Processes
ps [options]- ps shows the running processes.
kill [-signal] PID- kill sends a signal to a process by its PID — by default asking it to stop (SIGTERM).
top- top shows a live view of the processes using the most CPU and memory, plus load and uptime.
Shell
history [N]- history lists the commands you typed before, numbered.
echo [-n] [-e] text- echo prints text or the value of variables.
man command- man opens the built-in manual page of a command, with every option explained.
which command- which shows the full path of the program that runs when you type a command.
nano file- nano is a simple terminal text editor.
vim file- vim is a powerful keyboard-driven editor with modes: press i to type, Esc to stop typing, then :wq to save and quit or :q! to quit without saving.
Network
ssh [options] user@host- ssh opens an encrypted remote terminal on another machine.
ip [object] [command]- ip shows and changes network settings.
ping [-c N] host- ping checks whether a host is reachable by sending ICMP echo packets and measuring how long the replies take.
ss [options]- ss shows network connections and listening ports.
dig [@server] name [type]- dig asks DNS servers for records: A (IPv4), AAAA, MX (mail), TXT, NS and more.
curl [options] URL- curl sends HTTP (and other) requests from the terminal and prints the response — great for testing websites and APIs.
Security
base64 [-d] [file]- base64 encodes data into plain text characters and decodes it back with -d.
sha256sum [-c] file- sha256sum calculates a file's SHA-256 hash — a fingerprint that changes completely if even one byte changes.
md5sum file- md5sum calculates the MD5 hash of a file or text.