General OS
File System Navigation
Basic Navigation
pwd # Print working directory
cd /path/to/directory # Change directory
cd ~ # Go to home directory
cd - # Go to previous directory
cd .. # Go up one directory
ls # List directory contents
ls -la # List with details and hidden files
ls -lh # List with human-readable sizes
tree # Display directory tree
File Operations
# Creating files and directories
touch filename # Create empty file
mkdir dirname # Create directory
mkdir -p path/to/dir # Create directory with parents
mktemp # Create temporary file
# Copying and moving
cp file1 file2 # Copy file
cp -r dir1 dir2 # Copy directory recursively
mv file1 file2 # Move/rename file
mv file1 /path/to/ # Move file to directory
# Removing files
rm filename # Remove file
rm -rf dirname # Remove directory recursively (dangerous!)
rmdir dirname # Remove empty directory
File Permissions
# View permissions
ls -l filename # View file permissions
stat filename # Detailed file information
# Change permissions
chmod 755 filename # Set permissions (rwxr-xr-x)
chmod +x filename # Add execute permission
chmod -w filename # Remove write permission
chmod u+x,g-w,o-r file # Multiple permission changes
# Change ownership
chown user:group file # Change owner and group
chown user file # Change owner only
chgrp group file # Change group only
Text Processing
Viewing Files
cat filename # Display entire file
less filename # View file with pagination
head -n 10 filename # Show first 10 lines
tail -n 10 filename # Show last 10 lines
tail -f filename # Follow file changes (logs)
Searching and Filtering
grep "pattern" file # Search for pattern in file
grep -r "pattern" dir # Recursive search in directory
grep -i "pattern" file # Case-insensitive search
grep -v "pattern" file # Invert match (exclude pattern)
grep -n "pattern" file # Show line numbers
# Advanced grep
grep -E "pattern1|pattern2" file # Extended regex (OR)
grep -A 5 -B 5 "pattern" file # Show 5 lines before/after
# Other search tools
find /path -name "*.txt" # Find files by name
locate filename # Find files using database
which command # Find command location
whereis command # Find command, source, manual
Text Manipulation
sort filename # Sort lines
sort -n filename # Numeric sort
sort -r filename # Reverse sort
sort -u filename # Sort and remove duplicates
uniq filename # Remove duplicate lines
uniq -c filename # Count occurrences
cut -d',' -f1 file.csv # Extract first column (CSV)
cut -c1-10 filename # Extract characters 1-10
awk '{print $1}' file # Print first column
awk -F',' '{print $2}' file.csv # Use comma as delimiter
sed 's/old/new/g' file # Replace all occurrences
sed -i 's/old/new/g' file # Edit file in place
System Information
System Details
uname -a # Complete system information
uname -r # Kernel version
hostname # System hostname
hostnamectl # Detailed host information
lsb_release -a # Distribution information
cat /etc/os-release # OS release information
Hardware Information
lscpu # CPU information
lshw # Hardware information
lshw -short # Hardware summary
lspci # PCI devices
lsusb # USB devices
lsblk # Block devices
fdisk -l # Disk partitions
System Resources
free -h # Memory usage (human-readable)
df -h # Disk usage by filesystem
du -h /path # Directory size
du -sh * # Size of all items in current directory
lsof # List open files
lsof -i :80 # Show what's using port 80
Process Management
Process Information
ps aux # All processes
ps -ef # All processes (different format)
ps -u username # Processes for specific user
pgrep process_name # Find process ID by name
pidof process_name # Get PID of process
Process Control
kill PID # Terminate process
kill -9 PID # Force kill process
killall process_name # Kill all instances of process
pkill process_name # Kill process by name
# Job control
command & # Run in background
jobs # List background jobs
fg %1 # Bring job 1 to foreground
bg %1 # Send job 1 to background
nohup command & # Run command immune to hangups
Process Monitoring
top # Real-time process viewer
htop # Enhanced process viewer
atop # Advanced process monitor
iotop # I/O monitoring
Network Commands
Network Information
ip addr show # Show IP addresses
ip route show # Show routing table
ifconfig # Network interface configuration
netstat -tuln # Show listening ports
ss -tuln # Modern replacement for netstat
lsof -i # Show network connections
Network Utilities
ping hostname # Test connectivity
traceroute hostname # Trace network path
wget URL # Download file
curl URL # Transfer data from server
ssh user@hostname # Secure shell connection
scp file user@host:path # Secure copy over network
Archive and Compression
Tar Archives
tar -cvf archive.tar files # Create tar archive
tar -xvf archive.tar # Extract tar archive
tar -tvf archive.tar # List archive contents
tar -czvf archive.tar.gz files # Create compressed archive
tar -xzvf archive.tar.gz # Extract compressed archive
Compression
gzip filename # Compress file
gunzip filename.gz # Decompress file
zip archive.zip files # Create zip archive
unzip archive.zip # Extract zip archive
Environment and Variables
Environment Variables
env # Show all environment variables
echo $PATH # Show PATH variable
export VAR=value # Set environment variable
unset VAR # Remove environment variable
Shell Configuration
source ~/.bashrc # Reload bash configuration
alias ll='ls -la' # Create command alias
unalias ll # Remove alias
history # Show command history
!n # Execute command n from history
!! # Execute last command
Package Management
Debian/Ubuntu (apt)
sudo apt update # Update package list
sudo apt upgrade # Upgrade packages
sudo apt install package # Install package
sudo apt remove package # Remove package
sudo apt search pattern # Search for packages
Red Hat/CentOS (yum/dnf)
sudo yum update # Update packages
sudo yum install package # Install package
sudo yum remove package # Remove package
sudo yum search pattern # Search for packages
System Services
Systemd Services
systemctl status service # Check service status
systemctl start service # Start service
systemctl stop service # Stop service
systemctl restart service # Restart service
systemctl enable service # Enable service at boot
systemctl disable service # Disable service at boot
systemctl list-units # List all units
Cron Jobs
Cron Management
crontab -l # List cron jobs
crontab -e # Edit cron jobs
crontab -r # Remove all cron jobs
# Cron syntax: minute hour day month day-of-week command
# Example: 0 2 * * * /path/to/script # Run daily at 2 AM
Input/Output Redirection
Redirection
command > file # Redirect stdout to file
command >> file # Append stdout to file
command 2> file # Redirect stderr to file
command &> file # Redirect both stdout and stderr
command < file # Use file as input
command | command2 # Pipe output to another command
Useful Combinations
find /path -name "*.log" | xargs rm # Find and remove files
ps aux | grep process_name # Find specific process
cat file | sort | uniq # Sort and remove duplicates