Essential Linux CLI Tools
Essential Linux CLI Tools - Complete Beginner’s Guide
Welcome to the world of powerful Linux command-line tools! This guide will introduce you to modern CLI utilities that will supercharge your terminal experience. We’ll progress from basic system monitoring to advanced text processing and file management.
Why These Tools Matter
While Linux comes with excellent built-in tools, these modern alternatives offer enhanced features, better performance, and more intuitive output. Think of them as upgrades to your command-line arsenal.
Quick Installation Script
Before diving into individual tools, here’s a one-liner to install all these tools on Ubuntu:
sudo apt update && sudo apt install -y htop ncdu bat eza tldr ripgrep fd-find duf btop fzf jq tree neofetch
1. System Monitoring Tools
htop - Interactive Process Viewer
Replaces: top
htop is your gateway to understanding what’s happening on your system. It’s like top but with colors, mouse support, and a much friendlier interface.
Usage:
htop
Key Features:
- Color-coded CPU and memory usage
- Tree view of processes (press F5)
- Easy process killing (F9)
- Sorting by various metrics (F6)
Pro Tips:
- Press
hfor help - Press
tto toggle tree view - Press
/to search for processes - Use arrow keys and Page Up/Down to navigate
btop - Modern Resource Monitor
Enhanced alternative to: htop
btop is the newest generation of system monitors with beautiful graphs and extensive customization.
Usage:
btop
Why choose btop over htop:
- More detailed graphs
- Network monitoring built-in
- Disk I/O monitoring
- Modern, customizable interface
2. Disk Usage Analysis
ncdu - NCurses Disk Usage
Replaces: du
Understanding where your disk space goes is crucial. ncdu provides an interactive way to explore your filesystem usage.
Usage:
# Analyze current directory
ncdu
# Analyze specific directory
ncdu /home
# Analyze and save results for later
ncdu -o diskusage.txt /
Navigation:
- Use arrow keys to navigate
- Press Enter to enter directories
- Press
dto delete files/folders - Press
qto quit
duf - Disk Usage/Free Utility
Replaces: df
duf shows disk usage in a much more readable format than the traditional df command.
Usage:
# Show all mounted filesystems
duf
# Show only local filesystems
duf --only local
# Show specific filesystem
duf /home
3. File Operations & Navigation
eza - Modern ls Replacement
Replaces: ls
eza is a modern alternative for the venerable file-listing command-line program ls that ships with Unix and Linux operating systems, giving it more features and better defaults. It’s built on exa and has some new features such as hyperlink support.
Usage:
# Basic listing
eza
# Long format with details
eza -l
# Show all files including hidden
eza -la
# Tree view
eza --tree
# Show git status
eza --git
# Combine options for detailed tree view
eza -la --git --tree --level=2
# Show file sizes in human-readable format
eza -lh
# Show icons (if terminal supports it)
eza --icons
# Group directories first
eza --group-directories-first
Create useful aliases:
echo 'alias ll="eza -la --git --group-directories-first"' >> ~/.bashrc
echo 'alias lt="eza --tree --level=3"' >> ~/.bashrc
source ~/.bashrc
fd - Fast Find Alternative
Replaces: find
fd is a fast and user-friendly alternative to find with sensible defaults.
Usage:
# Find files by name (remember to use 'fdfind' on Ubuntu)
fd filename
# or if you set up the alias:
fdfind filename
# Find files by extension
fd -e txt
# Find in specific directory
fd pattern /path/to/search
# Execute command on found files
fd -e log -x rm
# Case-insensitive search
fd -i FILENAME
tree - Directory Tree Display
Bonus Tool
While not in your original list, tree is invaluable for visualizing directory structures.
Usage:
tree
tree -L 2 # Limit depth to 2 levels
tree -a # Show hidden files
tree -I 'node_modules|.git' # Ignore patterns
4. Text Processing & Search
ripgrep (rg) - Super Fast Grep
Replaces: grep
ripgrep is significantly faster than grep and comes with smart defaults.
Usage:
# Basic search
rg "search term"
# Search in specific file types
rg "function" -t py
# Case-insensitive search
rg -i "search term"
# Show line numbers and context
rg -n -C 3 "search term"
# Search in hidden files and directories
rg --hidden "search term"
# Exclude certain directories
rg "search term" -g '!node_modules'
bat - Better Cat
Replaces: cat
bat is like cat but with syntax highlighting, line numbers, and git integration.
Usage:
# Display file with syntax highlighting (use 'batcat' on Ubuntu)
bat file.py
# or if you set up the alias:
batcat file.py
# Show line numbers
bat -n file.py
# Display multiple files
bat file1.txt file2.txt
# Page through large files
bat large_file.log
# Show only specific line ranges
bat -r 10:20 file.txt
jq - JSON Processor
Essential for: JSON manipulation
jq is like sed for JSON data - incredibly powerful for processing JSON.
Usage:
# Pretty print JSON
echo '{"name":"John","age":30}' | jq .
# Extract specific field
curl -s api.github.com/users/octocat | jq .name
# Filter arrays
echo '[{"name":"John","age":30},{"name":"Jane","age":25}]' | jq '.[] | select(.age > 28)'
# Transform data
echo '{"users":[{"name":"John"},{"name":"Jane"}]}' | jq '.users | map(.name)'
5. Interactive Tools & Utilities
fzf - Fuzzy Finder
Enhances: Command history, file selection
fzf is a general-purpose command-line fuzzy finder that integrates with many tools.
Usage:
# Interactive file selection
fzf
# Search command history (Ctrl+R)
# Search files (Ctrl+T)
# Change directory (Alt+C)
# Use with other commands
vim $(fzf)
cd $(find . -type d | fzf)
# Preview files while browsing
fzf --preview 'bat --color=always {}'
Enable key bindings:
echo 'source /usr/share/doc/fzf/examples/key-bindings.bash' >> ~/.bashrc
echo 'source /usr/share/doc/fzf/examples/completion.bash' >> ~/.bashrc
tldr - Simplified Man Pages
Enhances: man
tldr provides practical examples for command-line tools instead of lengthy manual pages.
Usage:
# Get practical examples
tldr tar
tldr git
tldr ssh
tldr find
# Search for commands
tldr --search "compress"
# Update database (run this first time)
tldr --update
6. Monitoring & Utility Commands
watch - Execute Commands Repeatedly
Built-in tool worth highlighting
watch comes with most Linux distributions but is incredibly useful for monitoring changes.
Usage:
# Monitor disk space every 2 seconds
watch df -h
# Monitor network connections
watch -n 1 netstat -an
# Monitor log files
watch tail /var/log/syslog
# Monitor processes
watch 'ps aux | grep python'
# Highlight differences between updates
watch -d free -h
xargs - Build Command Lines
Built-in tool worth mastering
xargs is powerful for processing command output and building command lines.
Common Usage Patterns:
# Find and remove files
find . -name "*.tmp" | xargs rm
# Process files with multiple commands
find . -name "*.py" | xargs wc -l
# Handle filenames with spaces
find . -name "*.txt" -print0 | xargs -0 ls -l
# Parallel processing
echo -e "file1\nfile2\nfile3" | xargs -P 3 -I {} process_file {}
# Interactive mode
find . -name "*.log" | xargs -p rm
7. Bonus Tools Worth Considering
neofetch - System Information
Great for: Showing off your system
Usage:
neofetch
Creating Your Optimal Setup
1. Create Useful Aliases
Add these to your ~/.bashrc or ~/.zshrc:
# Modern replacements
alias ls='eza'
alias ll='eza -la --git --group-directories-first'
alias lt='eza --tree'
alias cat='bat'
alias find='fd'
alias grep='rg'
# Useful combinations
alias top='btop'
alias du='ncdu'
alias df='duf'
# Git helpers with fzf
alias gco='git checkout $(git branch | fzf)'
alias glg='git log --oneline | fzf --preview "git show {1}"'
2. Setup Your Environment
# Add to ~/.bashrc
# Enable fzf key bindings
source /usr/share/doc/fzf/examples/key-bindings.bash
source /usr/share/doc/fzf/examples/completion.bash
# Update tldr database regularly
tldr --update
# Set bat theme (optional)
export BAT_THEME="GitHub"
3. Practice Workflow
Here’s a typical workflow using these tools:
# 1. Check system resources
btop
# 2. Find large files eating disk space
ncdu /home
# 3. Search for specific files
fd -e log | head -10
# 4. List files with details
eza -la --git
# 5. Examine a file
bat /var/log/syslog
# 5. Search within files
rg "error" /var/log/
# 6. Process JSON data
curl -s api.github.com/users/octocat | jq .
# 7. Monitor a process
watch 'ps aux | grep nginx'
Conclusion
These modern CLI tools will transform your terminal experience. Start with the basics (htop, bat, exa, fd) and gradually incorporate others as you become comfortable. Remember:
- Don’t feel pressured to use all tools immediately
- Focus on tools that solve your specific problems
- Create aliases for tools you use frequently
- Keep learning - the command line is incredibly powerful
The key is consistency. Use these tools daily, and soon they’ll become second nature. Your productivity will increase dramatically, and you’ll wonder how you ever worked without them!
Quick Reference Card
| Task | Old Tool | New Tool | Quick Example |
|---|---|---|---|
| Process monitoring | top | htop/btop | htop |
| File listing | ls -la | eza -la | eza -la --git --group-directories-first |
| Text search | grep -r | rg | rg "pattern" |
| File search | find | fd | fd filename |
| File viewing | cat | bat | bat file.py |
| Disk usage | du -sh | ncdu | ncdu /home |
| Disk free | df -h | duf | duf |
| JSON processing | sed/awk | jq | jq .name |
| Fuzzy search | None | fzf | vim $(fzf) |
| Quick help | man | tldr | tldr git |
Happy command-lining! 🚀