🚀 The DevOps Daily Driver: Your Essential Command Cheat Sheet
Cloud & DevOps Engineer with hands-on expertise in cloud architecture, containerization, and Infrastructure as Code. I design automated pipelines, optimize infrastructure, and help teams adopt cloud-native solutions with confidence.
As a professional DevOps engineer, you live at the command line. Whether you're provisioning infrastructure, managing containers, or automating pipelines, speed and precision are paramount. Forget digging through documentation—this cheat sheet compiles the most critical, daily-use commands for the tools that form the backbone of modern DevOps.
Keep this handy. Your keyboard awaits!
🐧 Linux (The Foundation)
The operating system is the bedrock of our work. These commands are essential for file manipulation, system monitoring, and troubleshooting.
| Category | Command | Description |
| File/Text | ls -alh | List files with human-readable sizes and all details. |
grep "pattern" file.txt | Search for a pattern within a file. | |
cat file.txt | Display the entire content of a file. | |
tail -f logs/app.log | Watch the end of a log file in real-time. | |
vi/nano file.txt | Open a file for editing in the terminal. | |
| System Info | top or htop | Display a dynamic, real-time view of running processes and resource usage. |
df -h | Display disk space usage in human-readable format. | |
du -sh /path/ | Summarize disk usage of a specific directory. | |
| `ps aux | grep <process_name>` | |
| Networking | curl -I <url> | Get the HTTP headers for a URL (useful for quick checks). |
ssh user@host | Securely connect to a remote server. | |
netstat -tuln or ss -tuln | Display active network connections and listening ports. |
🐳 Docker (Container Management)
Docker is key to consistent environments. These commands manage images, containers, and volumes.
| Category | Command | Description |
| Containers | docker run -d -p 8080:80 --name my-app my-image:latest | Create and start a container in detached mode, mapping ports. |
docker ps | List running containers. Use docker ps -a for all (including stopped). | |
docker logs -f my-app | Follow the logs of a container. | |
docker exec -it my-app /bin/bash | Execute an interactive shell inside a running container. | |
docker stop my-app | Stop a running container. | |
docker rm my-app | Remove a stopped container. | |
| Images | docker build -t my-image:latest . | Build an image from a Dockerfile in the current directory. |
docker images | List local images. | |
docker pull my-image:tag | Download an image from a registry. | |
docker push my-repo/my-image:tag | Upload an image to a registry. | |
docker rmi <image_id> | Remove a local image. | |
| Cleanup | docker system prune | Clean up unused images, containers, networks, and build cache. |
🏗️ Terraform (Infrastructure as Code)
Provisioning infrastructure efficiently requires a deep understanding of the Terraform workflow.
| Command | Description |
terraform init | Initializes a Terraform working directory (downloads providers/modules). |
terraform validate | Checks configuration for syntax errors and consistency. |
terraform plan | Generates an execution plan showing what changes will be made (dry run). |
terraform apply | Applies the planned changes to create or update infrastructure. |
terraform apply -auto-approve | Skip the manual approval prompt (use cautiously in CI/CD). |
terraform destroy | Tears down all resources managed by the current configuration. |
terraform fmt | Rewrites configuration files to a canonical format (standard formatting). |
terraform output <name> | Display the value of a specific output variable. |
terraform state list | Lists all resources tracked in the current state file. |
☸️ Kubernetes (Orchestration with kubectl)
Kubernetes is the heart of many modern deployments. The kubectl command is your primary interface.
| Category | Command | Description | | :--- | :--- | | Viewing Resources | kubectl get pods | List all Pods in the current namespace (can use po). | | | kubectl get svc,deploy,rs | List services, deployments, and replica sets. | | | kubectl get all -n <namespace> | List common resources across a specific namespace. | | | kubectl describe pod <pod-name> | Show detailed status (events, container info, status). | | Logs & Access | kubectl logs -f <pod-name> | Follow the logs for a specific Pod. | | | kubectl exec -it <pod-name> -- /bin/bash | Get an interactive shell inside a running Pod. | | Management | kubectl apply -f deployment.yaml | Create/Update resources from a file (declarative). | | | kubectl delete -f deployment.yaml | Delete resources defined in a file. | | | kubectl rollout status deploy/<deployment-name> | Watch the status of a deployment rollout. | | | kubectl scale deploy <name> --replicas=3 | Scale a deployment immediately. | | Configuration | kubectl config use-context <context-name> | Switch to a different cluster context. | | | kubectl get secret <secret-name> -o jsonpath='{.data.key}' \| base64 -d | Decode and view a Secret key's value. |
⛑️ Helm (Package Manager for Kubernetes)
Helm charts simplify the deployment and management of applications on Kubernetes.
| Command | Description |
helm repo add <name> <url> | Add a remote chart repository. |
helm repo update | Fetch the latest charts from all repositories. |
helm install <release-name> <chart-name> | Deploy a new application instance (a "release"). |
helm install <release> <chart> -f values.yaml | Install, overriding default chart values with a custom file. |
helm upgrade <release-name> <chart-name> | Upgrade an existing release to a new chart version or updated values. |
helm rollback <release-name> <revision-number> | Roll back a release to a previous, stable revision. |
helm list or helm ls | List all releases (deployed applications) in the current namespace. |
helm uninstall <release-name> | Remove a release from the cluster, including all its resources. |
helm template <chart-name> --debug | Locally render the Kubernetes manifests (useful for debugging). |
💻 Bash Scripting (Automation Glue)
Bash is the essential language for writing simple, effective automation and glue scripts for CI/CD.
| Concept/Command | Example/Syntax | Description |
| Shebang | #!/bin/bash | Must be the first line to define the interpreter. |
| Variable | NAME="prod" echo "Deploying to $NAME" | Define and use a variable. |
| Execution | chmod +x script.sh ./script.sh | Grant execute permission and run the script. |
| Condition | if [ $? -eq 0 ]; then echo "Success"; fi | If statement to check exit code of the previous command ($?). |
| Loop | for i in 1 2 3; do echo $i; done | A simple for loop. |
| Command Output | DEPLOY_ID=$(uuidgen) | Store command output in a variable using $(). |
| Error Handling | set -e | Exit immediately if any command fails (non-zero exit code). |
| Functions | deploy() { ... } deploy | Define and call a simple function. |
🐍 Python (Advanced Automation)
Python is the go-to for complex automation tasks, especially when interacting with cloud APIs and data.
| Module/Function | Use Case for DevOps | Example Command/Syntax |
| requests | Interact with REST APIs (e.g., Jenkins, GitHub, Cloud APIs). | response = requests.get('<url>') |
| os | Interact with the Operating System (environment variables, files). | os.environ.get('ENV_VAR') |
| subprocess | Run external shell commands from within a Python script. | subprocess.run(['kubectl', 'get', 'pods']) |
| json | Handle JSON data structures, common in API responses. | data = json.loads(response.text) |
| yaml | Read/write YAML configuration files (e.g., Kubernetes manifests). | yaml.safe_load(file) |
| boto3 (AWS SDK) | Automate AWS cloud resources. | ec2 = boto3.client('ec2') |
| argparse | Handle Command Line Arguments in a structured way. | parser.add_argument('-i', '--image') |
| logging | Create structured and categorized logs for scripts. | logging.info('Deployment started') |
💡 Pro Tip for Every Tool
Remember the two most important flags that work for almost every command-line tool:
--help: Get a quick overview of the command's usage and available flags.- Example:
docker run --helporkubectl get --help
- Example:
-vor--version: Quickly check the installed version (crucial for compatibility checks).- Example:
terraform versionorhelm version
- Example: