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
--helpflag and has a manual page you can read withman. When in doubt, checkcommand --helporman 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> --helpto explore options. - Use
sudowisely and avoid destructive flags (likerm -rf) unless you are absolutely sure.
Navigation and Filesystems
- pwd — Print Working Directory
Prints the absolute path of your current directory.
pwd
- ls — List Directory Contents
Lists files. Use-lfor long format,-ato include hidden files,-hfor human‑readable sizes.
ls -lah
- cd — Change Directory
Navigate between directories.cd -returns to the previous directory.
cd /var/log
cd - # go back
- tree — Display Directory Tree
Recursively lists directory structure in a tree view. Install via your package manager if missing.
tree -L 2
- 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 {} +
- 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
- du — Disk Usage
Show file and directory sizes.-ssummarizes,-his human‑readable.
du -sh .
- df — Disk Free
Show filesystem disk space usage.
df -h
- lsblk — List Block Devices
Summarize block devices (disks/partitions) without mounting.
lsblk -f
- stat — File Status
Detailed metadata: size, permissions, timestamps, and more.
stat /etc/hosts
- 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--
- chown — Change Owner
Change file owner and/or group. Requires proper privileges (oftensudo).
sudo chown -R ubuntu:www-data /var/www
Files and Content
- cat — Concatenate and Print Files
View or concatenate files; often used in pipelines.
cat /etc/os-release
- 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
- head — Start of File
Show the first lines;-ncontrols the count.
head -n 20 README.md
- tail — End of File
Show the last lines;-ffollows new content as it’s written.
tail -f /var/log/nginx/access.log
- touch — Create or Update Timestamps
Create empty files or update timestamps.
touch newfile.txt
- mkdir — Make Directory
Create directories;-pcreates parents as needed.
mkdir -p projects/demo/src
- cp — Copy Files and Directories
Use-rfor directories,-ato preserve attributes.
cp config.example.yml config.yml
cp -a mydir mydir_backup
- mv — Move or Rename
Rename files or move them across directories.
mv draft.txt final.txt
mv *.log logs/
- rm — Remove Files and Directories
Delete files. Use-rfor directories,-ito prompt,-fto force.
rm -i notes.txt # safer
# rm -rf /path/to/dir # dangerous; double-check path before running
- ln — Create Links
Create hard or symbolic (soft) links.
ln -s /var/www/current /var/www/app
- tee — Split Output to File and Stdout
Write output to a file while still displaying it;-aappends.
echo "export EDITOR=vim" | sudo tee -a /etc/environment
- file — Identify File Type
Detects file type by content, not just extension.
file /bin/ls
Text Processing and Searching
- grep — Search Text
Search patterns in files and streams; use-rfor recursive,-icase-insensitive,-Efor extended regex.
grep -RIn "ERROR" /var/log
- sed — Stream Editor
Transform text (substitute, delete, insert).-iedits 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
- 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
- sort — Sort Lines
Sort alphanumerically;-nnumeric,-rreverse,-kchoose key/column.
sort -t, -k2,2n report.csv
- uniq — Unique Adjacent Lines
Counts or filters duplicates; input should be sorted for best results.
sort users.txt | uniq -c | sort -nr
- cut — Select Fields
Extract columns by delimiter or character position.
cut -d: -f1,7 /etc/passwd
- tr — Translate or Delete Characters
Change case, delete characters, squeeze repeats.
tr '[:lower:]' '[:upper:]' < names.txt
- wc — Word/Line/Byte Count
Summarize counts of input data.
wc -l access.log
- 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
- ss — Socket Statistics
Modern replacement fornetstat; inspect open ports and connections.
ss -tulpn # TCP/UDP listening ports with process info (requires sudo for full details)
Processes and System Information
- ps — Process Status
List processes; combine with grep or sort.
ps aux --sort=-%mem | head
- top — Interactive Process Viewer
Real-time view of CPU/memory usage; pressMto sort by memory,Pby CPU.
top
- free — Memory Usage
Show RAM and swap usage.
free -h
- uname — System Information
Kernel name/version and architecture.
uname -a
- 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
- kill — Send Signals to Processes
Terminate or control processes by PID;-TERMis graceful,-KILLis forceful.
kill -TERM 12345
# If a process ignores TERM (last resort):
kill -KILL 12345
- systemctl — Control systemd Services
Manage services on systemd-based systems.
sudo systemctl status nginx
sudo systemctl restart nginx
sudo systemctl enable nginx --now
- 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:
systemctlandjournalctlrequire systemd (used by most modern distros). On non-systemd systems, use service-specific tools (e.g.,service,/var/log, orrcscripts).
Networking and Remote Access
- 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
- ping — Test Connectivity
Send ICMP echo requests to test network reachability.
ping -c 4 8.8.8.8
- curl — Transfer Data with URLs
HTTP(S) requests, APIs, downloads. Use-Ifor headers,-Lto 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
- 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
- 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
- scp — Secure Copy
Copy files over SSH. Use-rfor directories.
scp -r ./site/ user@server:/var/www/site/
Archiving and Compression
- 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
- gzip — Compression Utility
Compress or decompress.gzfiles;gunzipis equivalent togzip -d.
gzip -k large.log # keep original with -k
gunzip large.log.gz
Pro Tips for Everyday Efficiency
- Explore help quickly:
man -k keywordsearches man-page names and descriptions. - Safety nets:
- Use
--to separate options from filenames (helps with names starting with-). - Prefer
rm -ior a trash utility in interactive sessions.
- Use
- Quoting rules:
- Single quotes (’…’) prevent expansion; double quotes ("…") allow variable and command substitution.
- Redirection and pipes:
cmd > fileoverwrite;cmd >> fileappend;cmd 2>&1merge stderr into stdout.
- Globbing:
- Use quotes to avoid shell glob expansion when passing patterns to tools like
greporfind.
- Use quotes to avoid shell glob expansion when passing patterns to tools like
- Environment:
- Temporarily set env vars:
VAR=value command; print all withenv.
- Temporarily set env vars:
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.