Linux Command Cheat Sheet
Essential Linux and Unix shell commands grouped by task: files, text, search, permissions, processes, disks and networking, with a worked example for each.
By the tools4free.dev team · Last reviewed 4 December 2026
How to read this cheat sheet
A shell command has the shape command [options] [arguments]. Options usually start with a dash: a short option is one letter after one dash (-l), and short options can be combined (-la means -l -a). Long options start with two dashes (--all). Arguments are the files, directories or text the command works on. Commands can be joined: a pipe (|) sends the output of one command into the next, > writes output to a file (replacing it), >> appends, and && runs the next command only if the first succeeded.
The tables below group the commands by task. Each row gives the command, what it does, and a typical example. Most of these are part of the GNU coreutils or are standard on every Linux distribution, and they behave the same on other Unix-like systems such as macOS with small differences in options. Commands that change or delete data are marked careful. Linux does not have a recycle bin at the command line, so a deleted file is usually gone.
The reference for any command is on your own machine: man <command> opens its manual page, and <command> --help prints a short summary. Online, the man7.org Linux man-pages and the GNU coreutils manual are the authoritative sources. To work out permission numbers, use the chmod calculator, to schedule jobs the cron builder, and for version control see the Git cheat sheet.
The commands you will use most
sudo in front of a command to run it with administrator rights, only when you need to and understand the command.Navigate and list
| Command | What it does | Example |
|---|---|---|
pwd | Prints the current directory. | pwd |
ls | Lists directory contents. -l gives details, -a shows hidden files, -h gives readable sizes. | ls -lah /var/log |
cd | Changes directory. cd alone goes to your home; cd - returns to the previous directory. | cd ~/projects |
tree | Shows a directory as a tree. Not installed everywhere. | tree -L 2 |
du | Shows disk use of files and directories. -s summarises, -h is readable. | du -sh * |
df | Shows free and used space on mounted file systems. | df -h |
Create, copy, move and delete
| Command | What it does | Example |
|---|---|---|
mkdir | Creates a directory. -p creates parents and does not fail if it exists. | mkdir -p site/css |
touch | Creates an empty file or updates a file's modification time. | touch notes.txt |
cp | Copies files. -r copies directories recursively. | cp -r src backup |
mv | Moves or renames files and directories. | mv old.txt new.txt |
rm | Deletes files. -r deletes directories recursively. Careful: no undo. Add -i to confirm each file. | rm -i old.log |
rmdir | Deletes an empty directory. | rmdir empty-folder |
ln -s | Creates a symbolic link. | ln -s /var/www/site current |
rsync | Copies and synchronises files efficiently, locally or over SSH. | rsync -av src/ backup/ |
View and process text
| Command | What it does | Example |
|---|---|---|
cat | Prints files, or joins them. | cat a.txt b.txt |
less | Pages through a file. Press q to quit and / to search. | less /var/log/syslog |
head | Prints the first lines, 10 by default. | head -n 20 data.csv |
tail | Prints the last lines. -f follows a file as it grows. | tail -f app.log |
wc | Counts lines, words and bytes. -l counts lines. | wc -l data.csv |
sort | Sorts lines. -n sorts numerically, -r reverses. | sort -n numbers.txt |
uniq | Removes adjacent duplicate lines. Sort first. -c counts them. | sort names.txt | uniq -c |
cut | Extracts columns by delimiter or position. | cut -d, -f1,3 data.csv |
tr | Translates or deletes characters. | echo hello | tr a-z A-Z |
sed | Edits a stream of text, often to substitute. | sed 's/foo/bar/g' file.txt |
awk | Processes text by fields with small programs. | awk '{print $1}' access.log |
diff | Compares two files line by line. | diff -u old.txt new.txt |
Search
| Command | What it does | Example |
|---|---|---|
grep | Finds lines that match a pattern. -i ignores case, -r searches directories, -n shows line numbers. | grep -rn "TODO" src/ |
find | Finds files by name, type, size or date. | find . -name "*.log" -mtime +30 |
which | Shows the path of a command. | which python3 |
locate | Finds files by name using a prebuilt database. Not on every system. | locate nginx.conf |
whereis | Shows the binary, source and manual locations of a command. | whereis ls |
Quote patterns that contain * or other special characters, as in find . -name "*.log", so the shell passes them to the command instead of expanding them itself.
Permissions and ownership
Each file has permissions for its owner, its group and others. Read is 4, write is 2 and execute is 1, and you add them: 7 is rwx, 6 is rw-, 5 is r-x, 4 is r--. So 755 means rwxr-xr-x and 644 means rw-r--r--.
| Command | What it does | Example |
|---|---|---|
chmod | Changes permissions, in numbers or symbols. | chmod 755 script.sh |
chmod +x | Makes a file executable. | chmod +x deploy.sh |
chown | Changes owner and group. | sudo chown alice:staff report.txt |
umask | Shows or sets the default permission mask for new files. | umask |
sudo | Runs a command as the superuser, or another user. | sudo apt update |
id | Shows your user and group IDs. | id |
whoami | Prints your user name. | whoami |
| Octal | Symbolic | Typical use |
|---|---|---|
644 | rw-r--r-- | Ordinary files, readable by everyone and writable only by the owner. |
755 | rwxr-xr-x | Programs, scripts and directories. |
600 | rw------- | Private files such as SSH private keys. |
700 | rwx------ | Private directories, for example ~/.ssh. |
Processes
| Command | What it does | Example |
|---|---|---|
ps | Lists processes. ps aux shows all processes with their owners. | ps aux | grep nginx |
top | Shows live process and resource use. Press q to quit. | top |
htop | A friendlier version of top. Not installed everywhere. | htop |
kill | Sends a signal to a process by its ID. The default is TERM, which asks it to stop. | kill 1234 |
kill -9 | Sends KILL, which stops the process at once with no cleanup. Use as a last resort. | kill -9 1234 |
pkill | Sends a signal by name. | pkill firefox |
jobs | Lists background jobs of the current shell. | jobs |
bg / fg | Resumes a stopped job in the background or foreground. | fg %1 |
nohup | Runs a command that survives the terminal being closed. | nohup ./job.sh & |
uptime | Shows how long the system has run and the load averages. | uptime |
free | Shows memory use. -h is readable. | free -h |
A trailing & starts a command in the background. Ctrl+C interrupts the foreground command, and Ctrl+Z suspends it.
Archives and compression
| Command | What it does | Example |
|---|---|---|
tar -czf | Creates a gzip-compressed archive. c create, z gzip, f file name. | tar -czf backup.tar.gz project/ |
tar -xzf | Extracts a gzip-compressed archive. | tar -xzf backup.tar.gz |
tar -tf | Lists an archive without extracting. | tar -tf backup.tar.gz |
gzip / gunzip | Compresses or decompresses one file. | gzip big.log |
zip / unzip | Creates or extracts ZIP archives. | unzip site.zip |
Networking
| Command | What it does | Example |
|---|---|---|
ping | Checks whether a host answers. Press Ctrl+C to stop, or use -c to limit packets. | ping -c 4 example.com |
curl | Transfers data using URLs. -I shows only headers, -O saves with the remote name. | curl -I https://example.com |
wget | Downloads files. | wget https://example.com/file.zip |
ssh | Logs in to a remote machine securely. | ssh user@host |
scp | Copies files over SSH. | scp file.txt user@host:/tmp/ |
ip addr | Shows network interfaces and addresses. | ip addr |
ss | Shows sockets and listening ports. -tulpn lists listening TCP and UDP. | ss -tulpn |
dig | Queries DNS records. Part of the bind-utils or dnsutils package. | dig example.com MX |
HTTP codes returned by curl are explained in the HTTP status codes reference, and the port numbers shown by ss are listed in the common ports reference.
System information and packages
| Command | What it does | Example |
|---|---|---|
uname -a | Prints kernel and system information. | uname -a |
date | Prints or sets the date and time. | date -u |
history | Shows previous commands. | history | tail |
man | Opens the manual page for a command. | man grep |
echo | Prints text or variables. | echo "$HOME" |
env | Prints environment variables. | env | sort |
apt | Package manager on Debian and Ubuntu. | sudo apt install curl |
dnf | Package manager on Fedora and recent Red Hat systems. | sudo dnf install curl |
systemctl | Controls services on systems that use systemd. | systemctl status nginx |
Keyboard shortcuts in the shell
- Tab completes a file or command name.
- Up and Down move through your command history, and Ctrl+R searches it.
- Ctrl+A and Ctrl+E jump to the start and end of the line.
- Ctrl+C stops the running command, Ctrl+D ends input or logs out, and Ctrl+L clears the screen.
Common mistakes
- Running rm -rf with a variable or wildcard you have not checked. Print the expansion first with echo or ls. A wrong path can delete far more than you expect.
- Spaces in file names. The shell splits arguments on spaces, so quote the name:
rm "my file.txt". - Using chmod 777. It lets everyone write to the file. Find the permission that is actually needed.
- Using sudo to silence an error. A permission error often means you are working in the wrong place. Understand the cause first.
- Forgetting that > overwrites.
> filereplaces the file. Use>>to append. - Using uniq without sort. It removes only adjacent duplicates.