Introduction

Whether you’re a developer, sysadmin, data scientist, or just curious about the command line, knowing the right Linux commands can save time and help you work more confidently. This guide covers the 50 most useful Linux commands, grouped by category, with concise explanations and copy‑paste‑ready examples. It focuses on commands available on most modern distributions and highlights best practices and safety tips along the way.

Tip: Nearly every command supports a --help flag and has a manual page you can read with man. When in doubt, check command --help or man command.

Table of Contents

  • Introduction
  • How to Use This Guide
  • Navigation and Filesystems
  • Files and Content
  • Text Processing and Searching
  • Processes and System Information
  • Networking and Remote Access
  • Archiving and Compression
  • Conclusion

How to Use This Guide

  • Read the short description to understand what each command does.
  • Try the examples in a safe directory (e.g., a temporary workspace).
  • Combine commands using pipes (|) and redirection (>, >>, <) to build powerful one‑liners.
  • Use man <command> or <command> --help to explore options.
  • Use sudo wisely and avoid destructive flags (like rm -rf) unless you are absolutely sure.

  1. pwd — Print Working Directory
    Prints the absolute path of your current directory.
pwd
  1. ls — List Directory Contents
    Lists files. Use -l for long format, -a to include hidden files, -h for human‑readable sizes.
ls -lah
  1. cd — Change Directory
    Navigate between directories. cd - returns to the previous directory.
cd /var/log
cd -    # go back
  1. tree — Display Directory Tree
    Recursively lists directory structure in a tree view. Install via your package manager if missing.
tree -L 2
  1. find — Search for Files
    Search by name, type, size, modification time, and execute actions on matches.
# Find files named '*.log' modified in the last day and print their sizes
find . -type f -name "*.log" -mtime -1 -exec du -h {} +
  1. man — Manual Pages
    Read documentation for commands, configuration files, and more.
man grep
# Search within man: press /pattern then n/N to move between matches
  1. du — Disk Usage
    Show file and directory sizes. -s summarizes, -h is human‑readable.
du -sh .
  1. df — Disk Free
    Show filesystem disk space usage.
df -h
  1. lsblk — List Block Devices
    Summarize block devices (disks/partitions) without mounting.
lsblk -f
  1. stat — File Status
    Detailed metadata: size, permissions, timestamps, and more.
stat /etc/hosts
  1. chmod — Change File Mode
    Modify file permissions using symbolic or numeric modes.
chmod u+x script.sh       # add execute for user
chmod 644 file.txt        # rw-r--r--
  1. chown — Change Owner
    Change file owner and/or group. Requires proper privileges (often sudo).
sudo chown -R ubuntu:www-data /var/www

Files and Content

  1. cat — Concatenate and Print Files
    View or concatenate files; often used in pipelines.
cat /etc/os-release
  1. less — Page Through Text
    Efficiently view large files with navigation and search.
less +F /var/log/syslog   # follow (like tail -f); press Ctrl-C to stop following
  1. head — Start of File
    Show the first lines; -n controls the count.
head -n 20 README.md
  1. tail — End of File
    Show the last lines; -f follows new content as it’s written.
tail -f /var/log/nginx/access.log
  1. touch — Create or Update Timestamps
    Create empty files or update timestamps.
touch newfile.txt
  1. mkdir — Make Directory
    Create directories; -p creates parents as needed.
mkdir -p projects/demo/src
  1. cp — Copy Files and Directories
    Use -r for directories, -a to preserve attributes.
cp config.example.yml config.yml
cp -a mydir mydir_backup
  1. mv — Move or Rename
    Rename files or move them across directories.
mv draft.txt final.txt
mv *.log logs/
  1. rm — Remove Files and Directories
    Delete files. Use -r for directories, -i to prompt, -f to force.
rm -i notes.txt           # safer
# rm -rf /path/to/dir     # dangerous; double-check path before running
  1. ln — Create Links
    Create hard or symbolic (soft) links.
ln -s /var/www/current /var/www/app
  1. tee — Split Output to File and Stdout
    Write output to a file while still displaying it; -a appends.
echo "export EDITOR=vim" | sudo tee -a /etc/environment
  1. file — Identify File Type
    Detects file type by content, not just extension.
file /bin/ls

Text Processing and Searching

  1. grep — Search Text
    Search patterns in files and streams; use -r for recursive, -i case-insensitive, -E for extended regex.
grep -RIn "ERROR" /var/log
  1. sed — Stream Editor
    Transform text (substitute, delete, insert). -i edits in place (use with caution).
sed -E 's/(foo)/bar/g' input.txt > output.txt
# In-place with backup:
sed -i.bak 's/Listen 80/Listen 8080/' /etc/apache2/ports.conf
  1. awk — Pattern Scanning and Processing
    Excellent for column-based data.
# Print first and third columns from a space-delimited file
awk '{print $1, $3}' data.txt
# Use -F to set delimiter
awk -F, '{sum+=$2} END {print sum}' sales.csv
  1. sort — Sort Lines
    Sort alphanumerically; -n numeric, -r reverse, -k choose key/column.
sort -t, -k2,2n report.csv
  1. uniq — Unique Adjacent Lines
    Counts or filters duplicates; input should be sorted for best results.
sort users.txt | uniq -c | sort -nr
  1. cut — Select Fields
    Extract columns by delimiter or character position.
cut -d: -f1,7 /etc/passwd
  1. tr — Translate or Delete Characters
    Change case, delete characters, squeeze repeats.
tr '[:lower:]' '[:upper:]' < names.txt
  1. wc — Word/Line/Byte Count
    Summarize counts of input data.
wc -l access.log
  1. xargs — Build and Execute Command Lines
    Convert standard input into arguments for other commands.
# Remove files listed by find, handling spaces safely
find . -type f -name "*.tmp" -print0 | xargs -0 rm -f
  1. ss — Socket Statistics
    Modern replacement for netstat; inspect open ports and connections.
ss -tulpn   # TCP/UDP listening ports with process info (requires sudo for full details)

Processes and System Information

  1. ps — Process Status
    List processes; combine with grep or sort.
ps aux --sort=-%mem | head
  1. top — Interactive Process Viewer
    Real-time view of CPU/memory usage; press M to sort by memory, P by CPU.
top
  1. free — Memory Usage
    Show RAM and swap usage.
free -h
  1. uname — System Information
    Kernel name/version and architecture.
uname -a
  1. sudo — Run Commands as Another User (Typically Root)
    Execute commands with elevated privileges; use sparingly.
sudo apt update
# Cache credentials; helpful before running a series of sudo commands
sudo -v
  1. kill — Send Signals to Processes
    Terminate or control processes by PID; -TERM is graceful, -KILL is forceful.
kill -TERM 12345
# If a process ignores TERM (last resort):
kill -KILL 12345
  1. systemctl — Control systemd Services
    Manage services on systemd-based systems.
sudo systemctl status nginx
sudo systemctl restart nginx
sudo systemctl enable nginx --now
  1. journalctl — Query systemd Journal
    View system logs; follow in real time with -f.
# Show recent logs for a service
journalctl -u ssh --since "1 hour ago"
journalctl -xe   # show recent errors with explanations

Note: systemctl and journalctl require systemd (used by most modern distros). On non-systemd systems, use service-specific tools (e.g., service, /var/log, or rc scripts).


Networking and Remote Access

  1. ip — Network Interface and Routing
    Configure and inspect IP addresses, routes, and links.
ip -br a         # brief addresses
ip route         # routing table
sudo ip addr add 192.168.1.50/24 dev eth0
  1. ping — Test Connectivity
    Send ICMP echo requests to test network reachability.
ping -c 4 8.8.8.8
  1. curl — Transfer Data with URLs
    HTTP(S) requests, APIs, downloads. Use -I for headers, -L to follow redirects.
curl -I https://example.com
curl -s https://api.github.com/repos/owner/repo | jq '.stargazers_count'
curl -fsSL https://example.com/install.sh | sudo bash
  1. wget — Non-Interactive Download Utility
    Great for downloading files and mirroring sites.
wget -c https://example.com/bigfile.iso   # resume with -c
wget -qO- https://example.com/page.html   # output to stdout
  1. ssh — Secure Shell
    Remote login and command execution; use keys for authentication.
ssh -i ~/.ssh/id_ed25519 user@server
# With SSH config (~/.ssh/config):
# Host prod
#   HostName 203.0.113.10
#   User ubuntu
ssh prod
  1. scp — Secure Copy
    Copy files over SSH. Use -r for directories.
scp -r ./site/ user@server:/var/www/site/

Archiving and Compression

  1. tar — Archive Files
    Create and extract tar archives; combine with gzip or zstd.
# Create gzip-compressed archive
tar -czf project.tar.gz project/
# List contents
tar -tf project.tar.gz
# Extract
tar -xzf project.tar.gz -C /tmp
  1. gzip — Compression Utility
    Compress or decompress .gz files; gunzip is equivalent to gzip -d.
gzip -k large.log       # keep original with -k
gunzip large.log.gz

Pro Tips for Everyday Efficiency

  • Explore help quickly: man -k keyword searches man-page names and descriptions.
  • Safety nets:
    • Use -- to separate options from filenames (helps with names starting with -).
    • Prefer rm -i or a trash utility in interactive sessions.
  • Quoting rules:
    • Single quotes (’…’) prevent expansion; double quotes ("…") allow variable and command substitution.
  • Redirection and pipes:
    • cmd > file overwrite; cmd >> file append; cmd 2>&1 merge stderr into stdout.
  • Globbing:
    • Use quotes to avoid shell glob expansion when passing patterns to tools like grep or find.
  • Environment:
    • Temporarily set env vars: VAR=value command; print all with env.

Conclusion

Mastering the Linux command line isn’t about memorizing everything—it’s about recognizing patterns, knowing where to find help, and practicing with real tasks. The 50 commands above cover the majority of what you’ll do daily: navigating and inspecting files, transforming text, managing processes and services, working over the network, and packaging data. Start with the basics (ls, cd, grep, less, tar), build pipelines with xargs and tee, and lean on man when you need deeper details. With these tools and a bit of curiosity, you’ll quickly become fluent and effective on any Linux system.