Linux command reference
Linux commands explained, with examples
What each command does, its syntax, the options you will really use, copy-ready examples and common questions. Try every one in the free online terminal.
Files
ls
ls lists the files and folders inside a directory. With -l it shows permissions, owner, size and date; with -a it also shows hidden files…
cd
cd (change directory) moves you into another folder. cd alone or cd ~ goes to your home folder, cd .. goes one level up and cd - returns…
pwd
pwd (print working directory) prints the full path of the folder you are currently in.
mkdir
mkdir creates new folders (directories). With -p it creates every missing parent folder in the path and does not complain if the folder…
touch
touch creates an empty file if it does not exist, or updates the last-modified time of an existing file.
cp
cp copies files and folders. Use -r to copy a folder with everything inside it.
mv
mv moves files and folders to another place, and is also how you rename them in Linux.
rm
rm permanently deletes files. With -r it deletes folders and everything in them. Linux has no recycle bin, so deleted files are gone.
tar
tar packs many files into one archive (.tar), usually compressed (.tar.gz). tar -czf creates, tar -xzf extracts.
Text
cat
cat prints the whole content of one or more files to the screen. It is also used to join files together.
less
less opens a file in a scrollable viewer so you can read big files page by page and search inside them with /word.
head
head shows the first lines of a file — 10 by default, or any number with -n.
tail
tail shows the last lines of a file (10 by default). tail -f keeps the file open and prints new lines live — perfect for watching logs.
wc
wc (word count) counts lines, words and bytes. wc -l is the quickest way to count lines.
sort
sort puts lines in order — alphabetically by default, numerically with -n, reversed with -r.
uniq
uniq removes repeated lines that are next to each other; with -c it counts them. Use it after sort.
cut
cut takes columns out of each line, split by a delimiter (-d) and choosing fields (-f).
awk
awk processes text column by column. awk '{print $1}' prints the first column; $NF is the last column.
sed
sed is a stream editor: most often used to find and replace text, e.g. sed 's/old/new/g' file.
tr
tr translates or deletes characters — e.g. lowercase to uppercase, or ROT13.
Search
grep
grep searches text and prints only the lines that match a word or regular expression. It is the most used command for log analysis.
find
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
chmod changes who can read (r=4), write (w=2) and execute (x=1) a file, for the owner, the group and everyone else. chmod 755 = rwxr-xr-x.
chown
chown changes the owner (and optionally the group) of files and folders. Usually needs sudo.
sudo
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
id shows your user id (uid), group id (gid) and every group you belong to.
df
df shows how much disk space is used and free on each mounted file system.
du
du shows how much space files and folders take. du -sh folder gives one human-readable total.
free
free shows how much RAM and swap memory is used and available.
uname
uname prints system information — with -a it shows the kernel name, version and architecture.
Processes
ps
ps shows the running processes. ps aux lists every process of every user with its CPU and memory use.
kill
kill sends a signal to a process by its PID — by default asking it to stop (SIGTERM). kill -9 forces it to stop immediately.
top
top shows a live view of the processes using the most CPU and memory, plus load and uptime.
Shell
history
history lists the commands you typed before, numbered. !! runs the last command again and !N runs command number N.
echo
echo prints text or the value of variables. With > or >> it writes text into files.
man
man opens the built-in manual page of a command, with every option explained.
which
which shows the full path of the program that runs when you type a command.
nano
nano is a simple terminal text editor. The shortcuts are shown at the bottom: Ctrl+O saves, Ctrl+X exits.
vim
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…
Network
ssh
ssh opens an encrypted remote terminal on another machine. It is how admins manage Linux servers.
ip
ip shows and changes network settings. ip a lists interfaces and IP addresses; ip r shows the routing table.
ping
ping checks whether a host is reachable by sending ICMP echo packets and measuring how long the replies take.
ss
ss shows network connections and listening ports. ss -tulpn lists every open TCP/UDP port and the program using it.
dig
dig asks DNS servers for records: A (IPv4), AAAA, MX (mail), TXT, NS and more.
curl
curl sends HTTP (and other) requests from the terminal and prints the response — great for testing websites and APIs.
Security
base64
base64 encodes data into plain text characters and decodes it back with -d. It is encoding, not encryption — anyone can decode it.
sha256sum
sha256sum calculates a file's SHA-256 hash — a fingerprint that changes completely if even one byte changes. -c checks files against a…
md5sum
md5sum calculates the MD5 hash of a file or text. MD5 is fine for spotting accidental changes but is not secure against attackers.