Linux Commands Cheat Sheet: 50+ Essential Commands (2026)

Linux Commands Cheat Sheet: 50+ Essential Commands (2026)

✅ Tested on Ubuntu 26.04 LTS, Debian 12, Arch Linux — Last updated: June 2026

Linux commands are the foundation of every sysadmin's toolkit, and mastering them will transform the way you interact with your system. Whether you're a complete beginner who just installed their first Linux distro or an experienced user who wants a quick reference, this Linux command cheat sheet covers the 50+ most essential commands you'll use every day.

This is not a list of obscure one-liners. Every command here is practical, commonly used, and explained with real examples you can copy and run immediately.

Contents
  1. File and Directory Navigation
    1. pwd — Print Working Directory
    2. ls — List Directory Contents
    3. cd — Change Directory
  2. File Management Commands
    1. cp — Copy Files and Directories
    2. mv — Move or Rename Files
    3. rm — Remove Files and Directories
    4. mkdir — Create Directories
    5. touch — Create Empty Files / Update Timestamps
    6. cat, less, more — View File Contents
  3. Permissions and Ownership
    1. chmod — Change File Permissions
    2. chown — Change File Owner
    3. sudo — Execute as Superuser
  4. Text Processing Commands
    1. grep — Search Text Patterns
    2. sed — Stream Editor (Find and Replace)
    3. awk — Text Processing and Reporting
    4. sort, uniq, wc
  5. Process Management
    1. ps — List Running Processes
    2. top and htop — Interactive Process Monitor
    3. kill — Terminate Processes
    4. Background and Foreground Jobs
  6. Networking Commands
    1. ip — Show and Configure Network Interfaces
    2. ss and netstat — Socket Statistics
    3. curl — Transfer Data from URLs
    4. wget — Download Files
    5. ping, traceroute, dig
  7. Disk and Storage Commands
  8. Package Management
    1. apt — Debian, Ubuntu, Linux Mint
    2. dnf/yum — Fedora, RHEL, CentOS
    3. pacman — Arch Linux
  9. System Information Commands
    1. systemctl — Service Management (systemd)
  10. Search and Find Commands
    1. find — Find Files and Directories
    2. locate — Fast File Search
  11. Archives and Compression
    1. tar — Archive Tool
    2. zip and unzip
  12. Pro Tips, Shortcuts, and Tricks
    1. Keyboard Shortcuts
    2. Piping and Redirection
    3. Useful Aliases to Add to ~/.bashrc
    4. Command Substitution and Variables
    5. Multiple Commands
  13. Troubleshooting Common Issues
    1. "Permission denied" errors
    2. "Command not found" errors
    3. Running out of disk space
  14. Frequently Asked Questions
    1. What is the difference between rm and rm -rf?
    2. How do I run a command as root without sudo prompting for a password?
    3. How do I see the full output of a command that scrolls past the screen?
    4. How do I cancel a running command?
    5. What's the fastest way to search through command history?
    6. Further Reading

These are the commands you'll type hundreds of times a day. Get them into muscle memory.

pwd — Print Working Directory

Shows your current location in the filesystem.

$ pwd
/home/jm/projects

ls — List Directory Contents

The most used command in Linux. It has many useful flags:

ls              # basic list
ls -l           # long format (permissions, size, date)
ls -la          # include hidden files (starting with .)
ls -lh          # human-readable file sizes (KB, MB, GB)
ls -lt          # sorted by modification time (newest first)
ls -lS          # sorted by file size (largest first)
ls -R           # recursive listing of all subdirectories
ls --color=auto # colorized output (usually the default)

Pro tip: Add alias ll='ls -lah' to your ~/.bashrc or ~/.zshrc to get a detailed, human-readable listing with a two-letter command.

cd — Change Directory

cd /etc             # go to /etc
cd ~                # go to home directory
cd ..               # go up one directory
cd ../..            # go up two directories
cd -                # go back to previous directory
cd /var/log/nginx   # absolute path

File Management Commands

cp — Copy Files and Directories

cp file.txt backup.txt          # copy a file
cp -r /source/dir /dest/dir     # copy directory recursively
cp -p file.txt dest/            # preserve timestamps and permissions
cp -u src dest                  # only copy if source is newer
cp -v file.txt dest/            # verbose (show what's being copied)

mv — Move or Rename Files

mv old_name.txt new_name.txt    # rename a file
mv file.txt /tmp/               # move to different directory
mv -i file.txt dest/            # prompt before overwriting
mv -n file.txt dest/            # never overwrite existing files

rm — Remove Files and Directories

Use with extreme caution. There is no recycle bin in the terminal.

rm file.txt             # delete a file
rm -r directory/        # delete directory and all contents
rm -rf /path/to/dir     # force delete without prompts (DANGEROUS)
rm -i file.txt          # prompt before each deletion
rm *.log                # delete all .log files in current directory

⚠️ Warning: rm -rf with the wrong path can destroy your system. Always double-check. Consider using trash-cli as a safer alternative.

mkdir — Create Directories

mkdir new_dir               # create a directory
mkdir -p a/b/c              # create nested directories (no error if exists)
mkdir -m 755 public_html    # create directory with specific permissions

touch — Create Empty Files / Update Timestamps

touch newfile.txt           # create empty file or update timestamp
touch file1 file2 file3     # create multiple files at once

cat, less, more — View File Contents

cat /etc/os-release         # print entire file to stdout
cat -n file.txt             # show with line numbers
less /var/log/syslog        # paged view (use q to quit, /search to find)
more file.txt               # older pager (less is better)
head -20 file.txt           # show first 20 lines
tail -50 /var/log/auth.log  # show last 50 lines
tail -f /var/log/nginx/access.log  # follow file in real time

Permissions and Ownership

Understanding Linux permissions is essential for security and system administration. Every file has three sets of permissions: owner (u), group (g), and others (o).

chmod — Change File Permissions

# Symbolic mode
chmod +x script.sh          # add execute permission for everyone
chmod u+x script.sh         # add execute for owner only
chmod 644 file.txt          # rw-r--r-- (owner read/write, others read)
chmod 755 directory/        # rwxr-xr-x (standard for directories)
chmod 600 private_key       # rw------- (owner read/write only)
chmod -R 755 /var/www/html  # recursive change

# Common permission sets:
# 777 = rwxrwxrwx (everyone can do everything — avoid!)
# 755 = rwxr-xr-x (standard executables)
# 644 = rw-r--r-- (standard files)
# 600 = rw------- (private files like SSH keys)

chown — Change File Owner

chown user file.txt              # change owner
chown user:group file.txt        # change owner and group
chown -R www-data:www-data /var/www/html  # recursive (common for web servers)
chown -R $USER:$USER ~/projects  # give current user ownership

sudo — Execute as Superuser

sudo apt update             # run command as root
sudo -u www-data php script.php  # run as a specific user
sudo -i                     # open root shell (use with caution)
sudo !!                     # re-run last command with sudo

Text Processing Commands

The real power of Linux lies in chaining text processing tools together via pipes (|). These commands are the building blocks.

grep — Search Text Patterns

grep "error" /var/log/syslog           # find lines containing "error"
grep -i "error" file.log               # case-insensitive search
grep -r "TODO" /home/user/projects/    # recursive search
grep -n "function" script.py           # show line numbers
grep -v "debug" app.log                # exclude lines with "debug"
grep -c "error" app.log                # count matching lines
grep -l "pattern" /etc/*.conf          # show filenames that match
grep -E "error|warning" app.log        # extended regex (OR)
grep -A3 "Exception" app.log           # show 3 lines after match
grep -B2 "FAILED" deploy.log           # show 2 lines before match

sed — Stream Editor (Find and Replace)

sed 's/old/new/' file.txt          # replace first occurrence per line
sed 's/old/new/g' file.txt         # replace all occurrences
sed -i 's/old/new/g' file.txt      # edit file in-place
sed '/pattern/d' file.txt          # delete lines matching pattern
sed -n '10,20p' file.txt           # print lines 10 to 20

awk — Text Processing and Reporting

awk '{print $1}' file.txt          # print first column
awk '{print $NF}' file.txt         # print last column
awk -F: '{print $1}' /etc/passwd   # use : as delimiter, print first field
awk '{sum += $1} END {print sum}' numbers.txt  # sum a column
df -h | awk '{print $5, $6}'       # extract disk usage columns

sort, uniq, wc

sort file.txt               # sort lines alphabetically
sort -n numbers.txt         # sort numerically
sort -rn file.txt           # reverse numeric sort
sort -u file.txt            # sort and remove duplicates
uniq file.txt               # remove consecutive duplicates
uniq -c file.txt            # count duplicates
wc -l file.txt              # count lines
wc -w file.txt              # count words
wc -c file.txt              # count bytes

Process Management

ps — List Running Processes

ps aux                      # all processes with details
ps aux | grep nginx         # find specific process
ps -ef --forest             # tree view of process hierarchy
pgrep nginx                 # get PID of process by name

top and htop — Interactive Process Monitor

top                         # built-in process monitor (press q to quit)
htop                        # improved version (install: sudo apt install htop)

# htop shortcuts:
# F9 or k  = kill process
# F6       = sort by column
# /        = search
# F2       = settings

kill — Terminate Processes

kill 1234               # send SIGTERM to PID 1234 (graceful)
kill -9 1234            # send SIGKILL (force kill)
kill -15 1234           # SIGTERM (same as default kill)
killall nginx           # kill all processes named nginx
pkill -f "python app"   # kill process matching pattern

Background and Foreground Jobs

command &            # run in background
jobs                 # list background jobs
fg %1                # bring job 1 to foreground
bg %1                # resume job 1 in background
Ctrl+Z               # suspend current foreground job
nohup command &      # run immune to hangups (survives logout)
disown %1            # detach job from shell

Networking Commands

ip — Show and Configure Network Interfaces

ip addr                             # show all IP addresses
ip addr show eth0                   # show specific interface
ip route                            # show routing table
ip link set eth0 up                 # bring interface up
sudo ip addr add 192.168.1.100/24 dev eth0  # add IP address

ss and netstat — Socket Statistics

ss -tulnp           # show listening ports with process names
ss -tuln            # TCP/UDP listening sockets
netstat -tulnp      # older alternative (may need: sudo apt install net-tools)
ss -s               # socket summary statistics

curl — Transfer Data from URLs

curl https://example.com                    # fetch URL
curl -I https://example.com                 # headers only
curl -o file.tar.gz https://example.com/file.tar.gz  # save to file
curl -L URL                                 # follow redirects
curl -u user:pass https://api.example.com   # basic auth
curl -X POST -H "Content-Type: application/json" 
  -d '{"key":"value"}' https://api.example.com/endpoint

wget — Download Files

wget https://example.com/file.tar.gz        # download file
wget -c https://example.com/large-file.iso  # resume interrupted download
wget -P /tmp/ URL                           # save to specific directory
wget -r -l2 https://example.com/            # recursive download (depth 2)

ping, traceroute, dig

ping google.com             # test connectivity
ping -c 4 8.8.8.8           # ping 4 times then stop
traceroute google.com       # trace network path (install: sudo apt install traceroute)
dig google.com              # DNS lookup
dig google.com MX           # query MX records
nslookup google.com         # simpler DNS lookup
host google.com             # another DNS tool

Disk and Storage Commands

df -h                       # disk space usage (human readable)
df -h /home                 # disk space for specific mountpoint
du -sh /var/log             # size of directory
du -sh * | sort -rh | head -10  # top 10 largest items in current dir
lsblk                       # list block devices
fdisk -l                    # list partitions (requires root)
mount                       # show mounted filesystems
free -h                     # RAM and swap usage
vmstat 1 5                  # memory/swap/IO statistics every 1s for 5 iterations

Package Management

Package management differs by distribution. Here are the commands for the most popular ones:

apt — Debian, Ubuntu, Linux Mint

sudo apt update                     # refresh package lists
sudo apt upgrade                    # upgrade all installed packages
sudo apt full-upgrade               # upgrade with dependency changes
sudo apt install nginx              # install package
sudo apt install -y nginx vim curl  # install multiple, skip prompts
sudo apt remove nginx               # remove package (keep config)
sudo apt purge nginx                # remove package and config
sudo apt autoremove                 # remove unused dependencies
apt search nginx                    # search available packages
apt show nginx                      # show package details
dpkg -l | grep nginx                # check if package is installed

dnf/yum — Fedora, RHEL, CentOS

sudo dnf update                 # update all packages
sudo dnf install nginx          # install package
sudo dnf remove nginx           # remove package
sudo dnf search nginx           # search packages
sudo dnf info nginx             # package information

pacman — Arch Linux

sudo pacman -Syu                # full system upgrade
sudo pacman -S nginx            # install package
sudo pacman -R nginx            # remove package
sudo pacman -Rs nginx           # remove with dependencies
sudo pacman -Ss nginx           # search packages
sudo pacman -Qi nginx           # installed package info
sudo pacman -Sc                 # clean package cache

System Information Commands

uname -a                    # kernel version and system info
uname -r                    # just the kernel version
cat /etc/os-release         # Linux distribution info
hostnamectl                 # hostname and system info (systemd)
lscpu                       # CPU information
lsmem                       # memory information
lspci                       # PCI devices (graphics cards, network cards)
lsusb                       # USB devices
dmidecode -t memory         # detailed RAM info (requires root)
uptime                      # how long system has been running
who                         # who is logged in
w                           # who is logged in + what they're doing
last                        # login history
history                     # command history
history | grep apt          # search command history

systemctl — Service Management (systemd)

sudo systemctl start nginx          # start service
sudo systemctl stop nginx           # stop service
sudo systemctl restart nginx        # restart service
sudo systemctl reload nginx         # reload config without full restart
sudo systemctl enable nginx         # start at boot
sudo systemctl disable nginx        # disable from boot
sudo systemctl status nginx         # check status
systemctl list-units --type=service # list all services
journalctl -u nginx                 # logs for specific service
journalctl -u nginx -f              # follow logs in real time
journalctl --since "1 hour ago"     # logs from last hour

find — Find Files and Directories

find /etc -name "*.conf"                    # find .conf files in /etc
find . -name "*.py" -type f                 # Python files in current dir
find /var/log -name "*.log" -mtime -7       # log files modified last 7 days
find . -size +100M                          # files larger than 100MB
find . -empty                              # empty files and directories
find . -perm 777                            # files with 777 permissions
find . -user www-data                       # files owned by www-data
find . -name "*.tmp" -delete                # find and delete .tmp files
find . -name "*.py" -exec grep -l "TODO" {} ;  # find Python files with TODO

locate — Fast File Search

locate nginx.conf           # find files by name (uses database)
sudo updatedb               # update the locate database
locate -i "*.conf"          # case-insensitive search

Archives and Compression

tar — Archive Tool

# Create archives
tar -czf archive.tar.gz directory/      # create gzip compressed tar
tar -cjf archive.tar.bz2 directory/     # create bzip2 compressed tar
tar -cJf archive.tar.xz directory/      # create xz compressed tar

# Extract archives
tar -xzf archive.tar.gz                 # extract gzip tar
tar -xzf archive.tar.gz -C /opt/        # extract to specific directory
tar -xjf archive.tar.bz2                # extract bzip2 tar

# List contents without extracting
tar -tzf archive.tar.gz

# Remember: c=create, x=extract, z=gzip, j=bzip2, J=xz, f=file, v=verbose

zip and unzip

zip -r archive.zip directory/       # create zip archive
zip -e archive.zip file.txt         # create encrypted zip
unzip archive.zip                   # extract zip
unzip archive.zip -d /opt/          # extract to specific directory
unzip -l archive.zip                # list contents

Pro Tips, Shortcuts, and Tricks

Keyboard Shortcuts

Ctrl+C          # cancel current command
Ctrl+Z          # suspend current command (use fg/bg to resume)
Ctrl+D          # exit shell (EOF)
Ctrl+L          # clear screen (same as 'clear')
Ctrl+A          # move cursor to beginning of line
Ctrl+E          # move cursor to end of line
Ctrl+U          # delete from cursor to beginning
Ctrl+K          # delete from cursor to end
Ctrl+W          # delete word before cursor
Ctrl+R          # reverse search command history
Tab             # auto-complete commands and filenames
Tab Tab         # show all completions
!!              # repeat last command
!$              # last argument of previous command
!apt            # run most recent apt command from history

Piping and Redirection

command1 | command2         # pipe output of cmd1 to cmd2
ls -la | grep ".sh"         # list only shell scripts
cat file.txt | wc -l        # count lines in file

# Redirection
command > file.txt          # redirect stdout to file (overwrite)
command >> file.txt         # append stdout to file
command 2> errors.txt       # redirect stderr to file
command &> all.txt          # redirect both stdout and stderr
command < input.txt         # read stdin from file

# Practical examples
ps aux | grep python | grep -v grep   # find Python processes
df -h | grep -v tmpfs                 # disk usage without tmpfs
cat /etc/passwd | cut -d: -f1 | sort  # list users sorted alphabetically

Useful Aliases to Add to ~/.bashrc

# Add these to ~/.bashrc or ~/.zshrc
alias ll='ls -lah'
alias la='ls -lA'
alias l='ls -CF'
alias ..='cd ..'
alias ...='cd ../..'
alias grep='grep --color=auto'
alias df='df -h'
alias du='du -h'
alias free='free -h'
alias update='sudo apt update && sudo apt upgrade -y'
alias ports='ss -tulnp'
alias myip='curl -s ifconfig.me'

# After editing, apply changes:
source ~/.bashrc

Command Substitution and Variables

echo $(date)                    # command substitution
echo "Today is $(date +%Y-%m-%d)"
FILENAME="backup_$(date +%Y%m%d).tar.gz"
echo $FILENAME
# backup_20260608.tar.gz

# Arithmetic
echo $((5 + 3))                 # prints 8
echo $((2 ** 10))               # prints 1024

Multiple Commands

cmd1 && cmd2        # run cmd2 only if cmd1 succeeds
cmd1 || cmd2        # run cmd2 only if cmd1 fails
cmd1; cmd2          # run cmd2 regardless of cmd1's exit code

# Practical examples:
sudo apt update && sudo apt upgrade -y     # update, then upgrade if update succeeded
mkdir -p /opt/app || echo "Directory exists"
cd /tmp && ls -la && du -sh *

Troubleshooting Common Issues

"Permission denied" errors

# Check permissions
ls -la file

# If you need root access:
sudo command

# If it's a script that won't run:
chmod +x script.sh
./script.sh

# Check if the filesystem is mounted read-only:
mount | grep ro

"Command not found" errors

# Find which package provides the command:
apt-file search binary_name     # Debian/Ubuntu
dnf provides binary_name        # Fedora

# Check if it's installed:
which nginx
type nginx
command -v nginx

# Check your PATH:
echo $PATH

Running out of disk space

# Find what's using space:
df -h
du -sh /var/log
du -sh /var/cache/apt
ls -lSh /var/log/

# Clean up on Debian/Ubuntu:
sudo apt autoremove
sudo apt autoclean
sudo journalctl --vacuum-size=200M  # trim systemd logs to 200MB

# Find large files:
find / -size +500M -type f 2>/dev/null | sort -rh | head -20

Frequently Asked Questions

What is the difference between rm and rm -rf?

rm deletes files. rm -r deletes directories recursively. Adding -f forces deletion without confirmation prompts. Never run rm -rf / or rm -rf /* — that's a system-destroying command.

How do I run a command as root without sudo prompting for a password?

Edit /etc/sudoers with sudo visudo and add: username ALL=(ALL) NOPASSWD: /path/to/command. Only do this for specific trusted commands.

How do I see the full output of a command that scrolls past the screen?

Pipe to less: command | less. Use arrow keys to scroll, q to quit, / to search.

How do I cancel a running command?

Press Ctrl+C to send SIGINT, which terminates most commands. If that doesn't work, press Ctrl+Z to suspend it, then run kill %1 to kill the suspended job.

What's the fastest way to search through command history?

Press Ctrl+R and start typing. Bash will search backwards through your history. Press Ctrl+R again to cycle to older matches. Press Enter to execute or the right arrow key to edit before running.

Now you have 50+ essential Linux commands with real examples you can use immediately. Bookmark this page — you'll be back. And if you're looking to level up your terminal workflow, check out our guide on how to use tmux to run multiple sessions without losing your work.


Go up

This site uses cookies for analytics and advertising (Google AdSense). By continuing to browse, you accept our use of cookies. Learn more