Basic commands
This guide covers essential Linux commands that every user should know.
π File and Directory Navigation
Directory Navigation
pwd # Print working directory
cd /path/to/directory # Change directory
cd .. # Go up one directory
cd ~ # Go to home directory
cd - # Go to previous directoryListing Files and Directories
ls # List files and directories
ls -l # Long format listing
ls -a # Show hidden files
ls -lh # Human-readable file sizes
ls -R # Recursive listing
ls -lt # Sort by modification timeFile Operations
touch file.txt # Create empty file
mkdir directory # Create directory
mkdir -p dir1/dir2 # Create parent directories
rm file.txt # Remove file
rm -r directory # Remove directory and contents
rm -f file.txt # Force remove file
cp source dest # Copy file
mv source dest # Move/rename fileπ File Viewing and Editing
View File Contents
cat file.txt # Display entire file
less file.txt # View file with pagination
head file.txt # Show first 10 lines
head -n 20 file.txt # Show first 20 lines
tail file.txt # Show last 10 lines
tail -f file.txt # Follow file updatesText Processing
grep pattern file # Search for pattern
grep -i pattern file # Case-insensitive search
grep -r pattern dir # Recursive search
wc file.txt # Count lines, words, chars
sort file.txt # Sort lines
uniq file.txt # Remove duplicate linesπ» System Information
System Status
date # Show current date/time
uptime # System uptime
uname -a # System information
df -h # Disk usage
free -h # Memory usage
top # Process monitor
htop # Interactive process viewerUser Information
whoami # Current username
who # Logged-in users
w # Who is doing what
id # User/group IDs
last # Recent loginsπ Process Management
Process Control
ps # Show processes
ps aux # Show all processes
kill PID # Terminate process
killall process_name # Kill all matching processes
pgrep pattern # Find process ID
pkill pattern # Kill matching processesπ Network Commands
Network Information
ip addr # Show IP addresses
ping host # Test connectivity
netstat -tuln # Show listening ports
ss -tuln # Modern netstat
curl url # Transfer data
wget url # Download filesπ‘ Tips and Tricks
Command History
history # Show command history !! # Repeat last command !number # Run command by history number ctrl + r # Search command historyKeyboard Shortcuts
Ctrl + C: Interrupt current processCtrl + Z: Suspend current processCtrl + D: Exit current shellCtrl + L: Clear screenCtrl + A: Go to beginning of lineCtrl + E: Go to end of line
Command Help
man command # Manual pages
command --help # Brief help
info command # Detailed documentation
whatis command # One-line descriptionπ― Best Practices
Safety First
Use
-iflag withrmfor interactive deletionMake backups before major operations
Test commands with sample data first
Efficiency
Use tab completion
Learn keyboard shortcuts
Create aliases for common commands
Organization
Keep home directory organized
Use meaningful file names
Document complex commands
π« Common Mistakes to Avoid
Running commands without understanding them
Using
rm -rfwithout careful considerationRunning commands as root unnecessarily
Forgetting to backup important data
Not using command history effectively
Last updated
Was this helpful?