File System Navigation

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Directory operations
pwd                     # Print working directory
ls                      # List files
ls -la                  # List all files with details
cd directory           # Change directory
cd ..                  # Go up one directory
cd ~                   # Go to home directory
mkdir directory        # Create directory
rmdir directory        # Remove empty directory
rm -rf directory       # Remove directory and contents

File Operations

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Basic file operations
touch file.txt         # Create empty file
cp source dest         # Copy file
mv source dest         # Move/rename file
rm file               # Remove file
cat file              # Display file contents
less file             # View file with pagination
head -n 10 file       # Show first 10 lines
tail -n 10 file       # Show last 10 lines
tail -f file          # Follow file updates

File Permissions

1
2
3
4
5
6
7
8
# Change permissions
chmod 755 file         # Set permissions (rwxr-xr-x)
chmod u+x file         # Add execute permission for user
chown user:group file  # Change file owner and group

# Permission numbers
# 4 (read) + 2 (write) + 1 (execute)
# Example: 755 means rwx for owner, rx for group and others

Text Processing

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Search and filter
grep pattern file      # Search for pattern
grep -r pattern dir    # Recursive search
grep -i pattern file   # Case-insensitive search

# Text manipulation
sed 's/old/new/g' file # Replace text
awk '{print $1}' file  # Print first column
sort file              # Sort lines
uniq                   # Remove duplicates
wc -l file            # Count lines

System Information

1
2
3
4
5
6
7
# System resources
top                    # Process viewer
htop                   # Enhanced process viewer
free -h               # Memory usage
df -h                 # Disk usage
du -sh directory      # Directory size
ps aux                # Process list

Network Operations

1
2
3
4
5
6
7
8
9
# Network commands
ping host             # Test connectivity
curl url              # HTTP requests
wget url              # Download files
netstat -tulpn        # Show active ports
ifconfig              # Network interfaces
ip addr               # Modern interface info
ssh user@host         # SSH connection
scp file user@host:   # Secure copy

SSH and Security

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Generate SSH key
ssh-keygen -t rsa -b 4096

# Copy SSH key to server
ssh-copy-id user@host

# Generate SSL/TLS keys
# Generate private key
openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:4096

# Extract public key
openssl rsa -pubout -in private_key.pem -out public_key.pem

# Generate CSR (Certificate Signing Request)
openssl req -new -newkey rsa:2048 -nodes -keyout domain.key -out domain.csr

Process Management

1
2
3
4
5
6
7
8
# Process control
ps aux | grep process  # Find process
kill pid              # Kill process
killall process       # Kill by name
nohup command &       # Run in background
bg                    # Background job
fg                    # Foreground job
jobs                  # List jobs

Package Management (Ubuntu/Debian)

1
2
3
4
5
6
7
# APT commands
apt update            # Update package list
apt upgrade           # Upgrade packages
apt install package   # Install package
apt remove package    # Remove package
apt search package    # Search packages
apt list --installed  # List installed packages

System Administration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# User management
sudo command          # Run as root
useradd username      # Create user
usermod -aG group user # Add user to group
passwd username       # Change password

# Service management
systemctl start service
systemctl stop service
systemctl status service
systemctl enable service

Bash Scripting Basics

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash

# Variables
NAME="John"
echo $NAME

# Conditionals
if [ "$NAME" = "John" ]; then
    echo "Hello John"
elif [ "$NAME" = "Jane" ]; then
    echo "Hello Jane"
else
    echo "Hello stranger"
fi

# Loops
for i in {1..5}; do
    echo $i
done

# While loop
while [ condition ]; do
    echo "Loop"
done

# Functions
function greet() {
    echo "Hello $1"
}
greet "World"

Useful Shortcuts

  • Ctrl + C: Interrupt current process
  • Ctrl + Z: Suspend current process
  • Ctrl + D: Exit current shell
  • Ctrl + L: Clear screen
  • Ctrl + R: Search command history
  • Ctrl + A: Go to beginning of line
  • Ctrl + E: Go to end of line
  • Ctrl + U: Clear line before cursor
  • Ctrl + K: Clear line after cursor

Environment Variables

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# View environment variables
env
echo $PATH
echo $HOME

# Set environment variable
export VAR="value"

# Add to PATH
export PATH=$PATH:/new/path

# Permanent changes (add to ~/.bashrc)
echo 'export VAR="value"' >> ~/.bashrc
source ~/.bashrc