---
title: "DevOps Command Reference Guide"
author: "Claude and JonC"
description: "Quick reference for DevOps commands"
published: "2026-02-24"
---

## Linux Commands

### Navigation & File System
| Command | Description | Example |
|---------|-------------|---------|
| `pwd` | Print working directory | `pwd` |
| `cd [path]` | Change directory | `cd /var/log` |
| `cd ..` | Go up one directory | `cd ..` |
| `cd ~` | Go to home directory | `cd ~` |
| `cd ~username` | Go to user's home directory | `cd ~devops_user` |
| `ls` | List files | `ls` |
| `ls -l` | List with details | `ls -l` |
| `ls -a` | List all (including hidden) | `ls -a` |
| `ls -la` | List all with details | `ls -la` |
| `ls -lah` | List all with human-readable sizes | `ls -lah` |
| `tree` | Display directory structure | `tree` |

### File & Directory Management
| Command | Description | Example |
|---------|-------------|---------|
| `touch [file]` | Create empty file | `touch newfile.txt` |
| `mkdir [dir]` | Create directory | `mkdir newfolder` |
| `mkdir -p [path]` | Create nested directories | `mkdir -p folder/subfolder` |
| `cp [src] [dest]` | Copy file | `cp file1.txt file2.txt` |
| `cp [src]/* [dest]` | Copy all files (wildcard) | `cp folderA/* folderB/` |
| `mv [old] [new]` | Move/rename file | `mv oldname.txt newname.txt` |
| `rm [file]` | Remove file | `rm file1.txt` |
| `rm -d [dir]` | Remove empty directory | `rm -d emptyfolder` |
| `rm -rf [dir]` | Remove directory recursively (DANGEROUS) | `rm -rf oldfolder` |
| `cat [file]` | Display file contents | `cat /etc/passwd` |

### Text Editors
| Command | Description | Example |
|---------|-------------|---------|
| `vi [file]` | Open file in vi editor | `vi config.txt` |
| `i` | Enter INSERT mode in vi | Press `i` |
| `:wq` | Save and quit vi | Type `:wq` |
| `:q!` | Quit without saving vi | Type `:q!` |

### User Management
| Command | Description | Example |
|---------|-------------|---------|
| `sudo useradd [user] -c "Name"` | Add user with full name | `sudo useradd jenkins -c "Jenkins User"` |
| `sudo passwd [user]` | Set user password | `sudo passwd devops_user` |
| `sudo groupadd [group]` | Create group | `sudo groupadd developers` |
| `sudo usermod [user] -aG [group]` | Add user to group | `sudo usermod sarah -aG developers` |

### Permissions & Ownership
| Command | Description | Example |
|---------|-------------|---------|
| `chmod [mode] [file]` | Change file permissions | `chmod 755 script.sh` |
| `chmod u=rwx [file]` | Set user permissions | `chmod u=rwx myfile` |
| `chmod g=rx [file]` | Set group permissions | `chmod g=rx myfile` |
| `chown [user] [file]` | Change file owner | `sudo chown devops_user myfile` |
| `chgrp [group] [file]` | Change file group | `sudo chgrp developers myfile` |

### Permission Octal Values
| Permission | Octal | Binary | Description |
|------------|-------|--------|-------------|
| `---` | 0 | 000 | No permissions |
| `--x` | 1 | 001 | Execute only |
| `-w-` | 2 | 010 | Write only |
| `-wx` | 3 | 011 | Write + Execute |
| `r--` | 4 | 100 | Read only |
| `r-x` | 5 | 101 | Read + Execute |
| `rw-` | 6 | 110 | Read + Write |
| `rwx` | 7 | 111 | Read + Write + Execute |

**Common Permission Examples:**
- `755` = rwxr-xr-x (Owner: all, Group: r+x, Others: r+x)
- `750` = rwxr-x--- (Owner: all, Group: r+x, Others: none)
- `644` = rw-r--r-- (Owner: r+w, Group: read, Others: read)
- `600` = rw------- (Owner: r+w, Group: none, Others: none)

### Networking
| Command | Description | Example |
|---------|-------------|---------|
| `ifconfig` | Display network configuration | `ifconfig` |
| `ip addr` | Display IP addresses | `ip addr` |
| `ping [host]` | Test network connectivity | `ping google.com` |
| `curl [url]` | Download/transfer data | `curl https://example.com/file` |
| `wget [url]` | Download file | `wget https://example.com/file.txt` |
| `netstat` | Network statistics | `netstat` |
| `ss` | Socket statistics | `ss` |

### Package Management (Red Hat/CentOS)
| Command | Description | Example |
|---------|-------------|---------|
| `sudo dnf update` | Update package list | `sudo dnf update` |
| `sudo dnf upgrade` | Upgrade installed packages | `sudo dnf upgrade` |
| `sudo dnf install [pkg]` | Install package | `sudo dnf install nginx` |
| `sudo dnf install -y [pkg]` | Install without prompts | `sudo dnf install -y tree` |
| `sudo yum install [pkg]` | Install (older systems) | `sudo yum install httpd` |

### Service Management (systemctl)
| Command | Description | Example |
|---------|-------------|---------|
| `sudo systemctl enable [service]` | Enable service at boot | `sudo systemctl enable nginx` |
| `sudo systemctl start [service]` | Start service | `sudo systemctl start nginx` |
| `sudo systemctl stop [service]` | Stop service | `sudo systemctl stop nginx` |
| `sudo systemctl restart [service]` | Restart service | `sudo systemctl restart nginx` |
| `sudo systemctl status [service]` | Check service status | `sudo systemctl status nginx` |

### System Information
| Command | Description | Example |
|---------|-------------|---------|
| `uname -a` | Display system information | `uname -a` |
| `df -h` | Display disk space (human-readable) | `df -h` |
| `top` | Display running processes | `top` |
| `ps` | Show processes | `ps aux` |
| `kill [pid]` | Kill process by ID | `kill 1234` |
| `sudo poweroff` | Shut down system | `sudo poweroff` |

---

## Git Commands

### Initial Setup
| Command | Description | Example |
|---------|-------------|---------|
| `git config --global user.name "Name"` | Set username | `git config --global user.name "John Doe"` |
| `git config --global user.email "email"` | Set email | `git config --global user.email "john@example.com"` |

### Repository Management
| Command | Description | Example |
|---------|-------------|---------|
| `git init` | Initialize repository | `git init` |
| `git clone [url]` | Clone repository | `git clone git@github.com:user/repo.git` |
| `git remote add origin [url]` | Link remote repository | `git remote add origin git@github.com:user/repo.git` |
| `git remote -v` | View remote repositories | `git remote -v` |

### Basic Workflow
| Command | Description | Example |
|---------|-------------|---------|
| `git status` | Check repository status | `git status` |
| `git add .` | Stage all changes | `git add .` |
| `git add [file]` | Stage specific file | `git add README.md` |
| `git commit -m "message"` | Commit changes | `git commit -m "Fixed bug"` |
| `git push` | Push to remote | `git push` |
| `git push origin [branch]` | Push specific branch | `git push origin main` |
| `git pull` | Pull from remote | `git pull` |
| `git pull origin [branch]` | Pull specific branch | `git pull origin main` |
| `git log` | View commit history | `git log` |

### Branching
| Command | Description | Example |
|---------|-------------|---------|
| `git branch` | List branches | `git branch` |
| `git branch [name]` | Create branch | `git branch feature-login` |
| `git checkout [branch]` | Switch to branch | `git checkout feature-login` |
| `git checkout -b [branch]` | Create and switch to branch | `git checkout -b feature-login` |
| `git switch [branch]` | Switch to branch (newer) | `git switch feature-login` |
| `git merge [branch]` | Merge branch into current | `git merge feature-login` |

### Merge Conflicts
When conflicts occur:
1. Edit files to resolve conflicts (remove markers: `<<<<<<<`, `=======`, `>>>>>>>`)
2. `git add [file]` - Stage resolved file
3. `git commit -m "Resolved merge conflict"` - Complete merge

### SSH Setup for GitHub
| Command | Description | Example |
|---------|-------------|---------|
| `ssh-keygen -t rsa -b 4096 -C "email"` | Generate SSH key | `ssh-keygen -t rsa -b 4096 -C "user@example.com"` |
| `eval "$(ssh-agent -s)"` | Start SSH agent | `eval "$(ssh-agent -s)"` |
| `ssh-add ~/.ssh/id_rsa` | Add key to agent | `ssh-add ~/.ssh/id_rsa` |
| `cat ~/.ssh/id_rsa.pub` | Display public key | `cat ~/.ssh/id_rsa.pub` |
| `ssh -T git@github.com` | Test connection | `ssh -T git@github.com` |

---

## AWS Commands & Concepts

### EC2 (Elastic Compute Cloud)
| Task | Description | Details |
|------|-------------|---------|
| Launch Instance | Create virtual server | Amazon Linux 2, t2.micro (free tier) |
| Key Pair | SSH authentication | Download .pem (Mac/Linux) or .ppk (Windows) |
| Connect via SSH | Access instance | `ssh -i keyfile.pem ec2-user@public-dns` |
| Default Username | EC2 login user | `ec2-user` (Amazon/RHEL), `ubuntu` (Ubuntu) |
| Security Groups | Virtual firewall | Configure inbound/outbound rules |

### Common EC2 Ports
| Service | Port | Protocol |
|---------|------|----------|
| SSH | 22 | TCP |
| HTTP | 80 | TCP |
| HTTPS | 443 | TCP |
| ICMP (Ping) | N/A | All ICMP - IPv4 |

### S3 (Simple Storage Service)
| Task | Description | Steps |
|------|-------------|-------|
| Create Bucket | Storage container | Unique name, select region |
| Upload Objects | Add files | Use Upload button |
| Public Access | Allow public viewing | Uncheck "Block Public Access" + Bucket Policy |
| Versioning | Keep file versions | Enable in Properties tab |
| Lifecycle Policies | Automate storage | Transition to Glacier (30 days), Delete (90 days) |
| Static Website | Host website | Enable in Properties, upload index.html |

### S3 Bucket Policy (Public Access)
```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::BUCKET_NAME/*"
    }
  ]
}
```

### IAM (Identity and Access Management)
| Task | Description | Example |
|------|-------------|---------|
| Create User | Add IAM user | Console access or Programmatic access |
| Attach Policy | Grant permissions | AmazonS3FullAccess, AmazonEC2FullAccess |
| Access Keys | API/CLI access | Access Key ID + Secret Access Key |
| Groups | Organize users | Create group, assign policies, add users |

### CloudWatch
| Task | Description | Example |
|------|-------------|---------|
| Monitor Metrics | View instance stats | CPU utilization, Network traffic |
| Create Alarm | Alert on thresholds | CPU > 70% |
| View Logs | Application logs | EC2 system logs |

### Security Groups
| Task | Description | Example |
|------|-------------|---------|
| Create Security Group | Define firewall rules | Allow SSH (22), HTTP (80) |
| Inbound Rules | Control incoming traffic | Source: 0.0.0.0/0 (anywhere) or specific IP |
| Outbound Rules | Control outgoing traffic | Usually allow all |
| Associate with Instance | Apply to EC2 | Select during launch or modify later |
| IP Restrictions | Limit by IP | Source: Your IP only |

### AWS CLI Login (EC2)
```bash
# Connect to EC2 instance
ssh -i /path/to/keyfile.pem ec2-user@ec2-XX-XX-XX-XX.compute-1.amazonaws.com

# Or using PuTTY (Windows)
# Host: ec2-XX-XX-XX-XX.compute-1.amazonaws.com
# Username: ec2-user
# Private key: keyfile.ppk
```

---

## Important Paths & Directories

### Linux File System
| Path | Description |
|------|-------------|
| `/` | Root of filesystem |
| `/root` | Root user home directory |
| `/home/username` | User home directory |
| `/etc` | Configuration files |
| `/var/log` | Log files |
| `/var/www/html` | Web server files (Apache) |
| `/bin` | Essential binaries |
| `/usr/bin` | User binaries |
| `/tmp` | Temporary files |

### Special Characters
| Character | Meaning | Example |
|-----------|---------|---------|
| `/` | Root directory or path separator | `/home/user` |
| `~` | Home directory | `cd ~` |
| `.` | Current directory | `./script.sh` |
| `..` | Parent directory | `cd ..` |
| `*` | Wildcard (any characters) | `*.txt` |

---

## Quick Tips

### The Three "Roots" in Linux
1. **Root User** - Administrator account
2. **Root Filesystem** - `/` at top of hierarchy
3. **Root Home Folder** - `/root` directory

### Absolute vs Relative Paths
- **Absolute**: Starts with `/` (e.g., `/home/user/file.txt`)
- **Relative**: From current location (e.g., `../folder/file.txt`)

### Dangerous Commands
⚠️ **NEVER RUN**: `sudo rm -rf /` - Deletes entire system!

### Git Workflow
1. Make changes
2. `git add .`
3. `git commit -m "message"`
4. `git push origin branch-name`

### AWS Free Tier
- EC2: t2.micro (750 hours/month)
- S3: 5GB storage
- Always verify free tier eligibility!