DevOps Cheatsheet
Git CLI
git initInitialize a new Git repository
git clone repository-urlClone a repository from a remote source
git statusShow the current status of the working directory and staging area
git add file-nameStage changes to be committed
git add .Stage all changes in the working directory
git commit -m 'commit message'Commit staged changes with a message
git push origin branch-namePush local commits to a remote branch
git pull origin branch-namePull changes from a remote repository to the local branch
git fetch originFetch changes from a remote repository without merging
git merge branch-nameMerge another branch into the current branch
git branchList all branches in the repository
git branch branch-nameCreate a new branch
git checkout branch-nameSwitch to a different branch
git checkout -b branch-nameCreate a new branch and switch to it
git logView the commit history
git reset --hard commit-hashReset the current branch to a specific commit
git stashStash changes that are not yet committed
git stash applyReapply stashed changes
git remote add origin repository-urlAdd a remote repository
git remote -vList remote repositories
git tag tag-nameCreate a new tag for the current commit
git diffShow the differences between files in the working directory and the staging area
git rebase branch-nameReapply commits on top of another branch
git rm file-nameRemove a file from the working directory and staging area
Kubernetes CLI (kubectl & kubeadm)
kubectl get podsList all pods in the current namespace
kubectl get pods --all-namespacesList all pods across all namespaces
kubectl describe pod pod-nameDisplay detailed information about a specific pod
kubectl logs pod-nameGet logs from a specific pod
kubectl exec -it pod-name -- /bin/bashRun a command inside a running pod (e.g., open a shell)
kubectl get servicesList all services in the current namespace
kubectl get deploymentsList all deployments in the current namespace
kubectl create deployment deployment-name --image=image-nameCreate a new deployment
kubectl delete pod pod-nameDelete a specific pod
kubectl apply -f file.yamlApply a configuration from a YAML file
kubectl delete -f file.yamlDelete resources from a YAML file
kubectl get nodesList all nodes in the cluster
kubectl cordon node-nameMark a node as unschedulable
kubectl drain node-name --ignore-daemonsetsSafely evict all pods from a node for maintenance
kubectl uncordon node-nameMark a node as schedulable again
kubectl scale deployment deployment-name --replicas=5Scale a deployment to a specific number of replicas
kubectl expose deployment deployment-name --port=80 --target-port=8080Expose a deployment as a service
kubectl get namespacesList all namespaces
kubectl config get-contextsList all available contexts
kubectl config use-context context-nameSwitch to a specific context
kubectl rollout status deployment deployment-nameCheck the status of a deployment rollout
kubectl port-forward pod-name 8080:80Forward a local port to a port on a pod
kubectl top nodesShow CPU and memory usage for nodes
kubectl top podsShow CPU and memory usage for pods
kubeadm initInitialize a Kubernetes control-plane node
kubeadm join control-plane-ip:6443 --token token --discovery-token-ca-cert-hash sha256:hashJoin a worker node to the Kubernetes cluster
kubeadm resetReset all kubeadm-managed cluster state
kubeadm token createCreate a new token for joining nodes
kubeadm token listList all tokens for joining nodes
kubeadm config viewView the kubeadm configuration
kubeadm upgrade planCheck available upgrades for the control-plane node
kubeadm upgrade apply vX.X.XUpgrade the Kubernetes control-plane node to a specific version
Docker CLI
docker loginLog in to Docker Hub or another registry
docker pull image-namePull an image from a Docker registry
docker imagesList all downloaded Docker images
docker psList all running containers
docker ps -aList all containers (running and stopped)
docker run -d --name container-name image-nameRun a container in detached mode
docker run -it --name container-name image-nameRun a container in interactive mode with a terminal
docker exec -it container-name bashRun a bash shell inside a running container
docker stop container-nameStop a running container
docker start container-nameStart a stopped container
docker rm container-nameRemove a stopped container
docker rmi image-nameRemove an image
docker logs container-nameView logs of a running or stopped container
docker build -t image-name .Build a Docker image from a Dockerfile
docker-compose upStart services defined in a docker-compose.yml file
docker-compose downStop and remove containers, networks, and volumes created by `docker-compose up`
docker volume lsList all Docker volumes
docker network lsList all Docker networks
docker inspect container-nameGet detailed information about a container
docker system pruneRemove all unused containers, networks, images, and volumes
Terraform CLI
terraform --versionDisplay the Terraform version
terraform initInitialize a new or existing Terraform working directory
terraform validateValidate the configuration files
terraform planCreate an execution plan
terraform applyApply the changes required to reach the desired state of the configuration
terraform destroyDestroy all the resources managed by Terraform
terraform showShow the current state or plan
terraform fmtFormat Terraform configuration files to a canonical format
terraform state listList all resources in the state file
terraform state show resource-nameShow details of a resource in the state file
terraform taint resource-nameMark a resource for recreation during the next apply
terraform untaint resource-nameMark a resource as not needing recreation
terraform import resource-name idImport existing infrastructure into Terraform
terraform outputDisplay the output values from the Terraform state
terraform workspace listList all Terraform workspaces
terraform workspace new workspace-nameCreate a new workspace
terraform workspace select workspace-nameSelect an existing workspace
terraform workspace delete workspace-nameDelete a workspace
terraform plan -out=plan.tfplanCreate an execution plan and save it to a file
terraform apply plan.tfplanApply a previously created execution plan
terraform validate -jsonValidate configuration files and output results in JSON format
terraform graphGenerate a visual representation of the dependency graph
terraform consoleStart an interactive console for Terraform expressions
AWS CLI
aws configureConfigure AWS CLI with access key, secret key, region, and output format
aws ec2 describe-instancesList EC2 instances (AWS)
aws s3 cp file s3://bucket-nameCopy files to an S3 bucket (AWS)
aws s3 ls s3://bucket-nameList objects in an S3 bucket (AWS)
aws s3 sync ./local-folder s3://bucket-nameSync a local folder to an S3 bucket (AWS)
aws eks get-token --cluster-name cluster-nameGet an authentication token for an EKS cluster (AWS)
aws iam list-usersList all IAM users (AWS)
aws ec2 start-instances --instance-ids i-1234567890abcdef0Start an EC2 instance (AWS)
aws ec2 stop-instances --instance-ids i-1234567890abcdef0Stop an EC2 instance (AWS)
aws lambda invoke --function-name function-name output.txtInvoke a Lambda function (AWS)
aws cloudformation describe-stacksList CloudFormation stacks (AWS)
aws rds describe-db-instancesList RDS database instances (AWS)
aws elb describe-load-balancersList Elastic Load Balancers (AWS)
aws cloudwatch describe-alarmsList CloudWatch alarms (AWS)
aws ec2 create-key-pair --key-name key-nameCreate a new EC2 key pair (AWS)
aws ec2 describe-security-groupsList EC2 security groups (AWS)
aws ec2 allocate-addressAllocate an Elastic IP address (AWS)
aws ec2 describe-volumesList EC2 volumes (AWS)
aws route53 list-hosted-zonesList Route 53 hosted zones (AWS)
aws ecr get-login-password --region region | docker login --username AWS --password-stdin your_account_id.dkr.ecr.region.amazonaws.comLog in to AWS Elastic Container Registry (AWS)
DigitalOcean CLI
doctl auth initConfigure DigitalOcean CLI by adding your API token
doctl account getRetrieve account information (DigitalOcean)
doctl compute droplet listList all Droplets (DigitalOcean)
doctl compute droplet create droplet-name --region nyc3 --image ubuntu-20-04-x64 --size s-1vcpu-1gb --ssh-keys key-idCreate a new Droplet (DigitalOcean)
doctl compute droplet delete droplet-idDelete a Droplet (DigitalOcean)
doctl compute ssh droplet-idSSH into a Droplet (DigitalOcean)
doctl compute snapshot listList all snapshots (DigitalOcean)
doctl compute snapshot create droplet-id --name snapshot-nameCreate a snapshot of a Droplet (DigitalOcean)
doctl compute volume listList all volumes (DigitalOcean)
doctl compute volume create volume-name --size 10GiB --region nyc1Create a new block storage volume (DigitalOcean)
doctl kubernetes cluster listList Kubernetes clusters (DigitalOcean)
doctl kubernetes cluster kubeconfig save cluster-nameRetrieve and save the kubeconfig file for a Kubernetes cluster (DigitalOcean)
doctl databases listList all managed databases (DigitalOcean)
doctl databases create db-name --engine pg --region nyc3Create a managed database (PostgreSQL) (DigitalOcean)
doctl projects listList all projects (DigitalOcean)
doctl projects create --name project-name --purpose web --environment productionCreate a new project (DigitalOcean)
doctl compute firewall listList all firewalls (DigitalOcean)
doctl compute firewall create --name firewall-name --inbound-rules 'protocol:tcp,ports:22,address:0.0.0.0/0'Create a new firewall (DigitalOcean)
doctl compute load-balancer listList all load balancers (DigitalOcean)
doctl compute load-balancer create --name lb-name --region nyc3 --droplet-ids droplet-idCreate a new load balancer (DigitalOcean)
Google Cloud CLI (gcloud)
gcloud initInitialize the Google Cloud CLI and authenticate
gcloud auth loginLogin to Google Cloud account
gcloud config set project PROJECT_IDSet the active project for gcloud (GCP)
gcloud compute instances listList all Compute Engine instances (GCP)
gcloud compute instances create instance-name --zone=ZONECreate a new Compute Engine instance (GCP)
gcloud compute instances delete instance-name --zone=ZONEDelete a Compute Engine instance (GCP)
gcloud compute ssh instance-name --zone=ZONESSH into a Compute Engine instance (GCP)
gcloud compute disks listList all Compute Engine disks (GCP)
gcloud compute disks create disk-name --size=10GB --zone=ZONECreate a new Compute Engine disk (GCP)
gcloud container clusters listList all Kubernetes Engine clusters (GCP)
gcloud container clusters create cluster-name --zone=ZONECreate a new Kubernetes cluster (GCP)
gcloud container clusters get-credentials cluster-name --zone=ZONEGet credentials for a Kubernetes Engine cluster (GCP)
gcloud functions deploy function-name --runtime=nodejs10 --trigger-http --allow-unauthenticatedDeploy a Google Cloud Function (GCP)
gcloud functions listList all deployed Cloud Functions (GCP)
gcloud sql instances listList all Cloud SQL instances (GCP)
gcloud sql instances create instance-name --tier=db-f1-micro --region=REGIONCreate a new Cloud SQL instance (GCP)
gcloud storage buckets listList all Cloud Storage buckets (GCP)
gsutil cp file gs://bucket-nameCopy a file to a Cloud Storage bucket (GCP)
gcloud pubsub topics listList all Pub/Sub topics (GCP)
gcloud pubsub subscriptions listList all Pub/Sub subscriptions (GCP)
Azure CLI
az loginAuthenticate to your Azure account
az account set --subscription SUBSCRIPTION_IDSet the active Azure subscription
az vm listList all virtual machines (Azure)
az vm create --resource-group resource-group-name --name vm-name --image UbuntuLTSCreate a new virtual machine (Azure)
az vm delete --resource-group resource-group-name --name vm-nameDelete a virtual machine (Azure)
az vm start --resource-group resource-group-name --name vm-nameStart a virtual machine (Azure)
az vm stop --resource-group resource-group-name --name vm-nameStop a virtual machine (Azure)
az network vnet listList all virtual networks (Azure)
az network vnet create --name vnet-name --resource-group resource-group-name --address-prefix 10.0.0.0/16Create a new virtual network (Azure)
az storage account listList all storage accounts (Azure)
az storage blob upload --account-name account-name --container-name container-name --name blob-name --file path/to/fileUpload a blob to Azure Blob storage (Azure)
az storage blob download --account-name account-name --container-name container-name --name blob-name --file path/to/fileDownload a blob from Azure Blob storage (Azure)
az aks listList all Kubernetes clusters (Azure)
az aks create --resource-group resource-group-name --name cluster-name --node-count 1 --enable-addons monitoring --generate-ssh-keysCreate a new Kubernetes cluster (Azure)
az aks get-credentials --resource-group resource-group-name --name cluster-nameGet credentials for a Kubernetes cluster (Azure)
az sql server listList all SQL servers (Azure)
az sql server create --name server-name --resource-group resource-group-name --location location --admin-user admin-username --admin-password admin-passwordCreate a new SQL server (Azure)
az functionapp listList all Function Apps (Azure)
az functionapp create --resource-group resource-group-name --consumption-plan-location location --runtime node --name functionapp-name --storage-account storage-account-nameCreate a new Function App (Azure)
az group listList all resource groups (Azure)
az group create --name resource-group-name --location locationCreate a new resource group (Azure)
Linux CLI for DevOps
ls -lahList directory contents in human-readable format, including hidden files
cd /path/to/directoryChange to a specific directory
mkdir directory-nameCreate a new directory
rm -rf directory-nameRecursively delete a directory and its contents
cp source-file destinationCopy files or directories
mv source-file destinationMove or rename files or directories
chmod 755 file-nameChange file permissions
chown user:group file-nameChange file ownership
ps auxList all running processes
topMonitor system processes and resource usage in real time
htopInteractive process viewer (if installed)
df -hDisplay disk space usage in human-readable format
du -sh directory-nameDisplay the size of a directory
free -hDisplay available and used memory
grep 'search-string' file-nameSearch for a string within a file
find /path -name file-nameFind files or directories by name
tar -czvf archive-name.tar.gz directory-nameCompress a directory into a tar.gz archive
tar -xzvf archive-name.tar.gzExtract a tar.gz archive
curl -O urlDownload a file from the internet using curl
wget urlDownload a file from the internet using wget
ssh user@remote-server-ipConnect to a remote server via SSH
scp file-name user@remote-server:/pathCopy a file to a remote server via SCP
rsync -avz source destinationSync files between local and remote systems
systemctl status service-nameCheck the status of a service
systemctl start service-nameStart a service
systemctl stop service-nameStop a service
systemctl restart service-nameRestart a service
journalctl -xeView detailed logs from system services
crontab -eEdit the cron jobs for the current user
netstat -tulnShow listening ports and active connections
ss -tulnShow socket statistics, including listening ports
ping hostname-or-ipPing a remote server to check connectivity
traceroute hostname-or-ipTrace the route packets take to a network host
iptables -LList firewall rules using iptables
Monitoring & Logging
prometheus --config.file=prometheus.ymlStart Prometheus with a config file
grafana-server --config=/etc/grafana/grafana.iniStart Grafana server
elasticsearchStart Elasticsearch
kibanaStart Kibana
logstash -f logstash.confStart Logstash with a config file
filebeat -e -c filebeat.ymlStart Filebeat with a config file
curl -X GET "localhost:9200/_cat/health"Check Elasticsearch cluster health
journalctl -u service-nameView logs for a specific systemd service
Ansible CLI
ansible --versionDisplay the Ansible version
ansible localhost -m pingPing localhost to test connectivity
ansible all -i inventory.ini -m pingPing all hosts listed in the inventory file
ansible-playbook playbook.ymlRun a playbook
ansible-playbook playbook.yml --checkRun a playbook in check mode (dry run)
ansible-playbook playbook.yml --diffShow differences between the current and desired states
ansible-galaxy collection install collection-nameInstall an Ansible collection from Galaxy
ansible-galaxy role install role-nameInstall an Ansible role from Galaxy
ansible-inventory --listList all inventory hosts and their variables
ansible-inventory -i inventory.ini --graphDisplay the inventory as a graph
ansible-vault encrypt file.ymlEncrypt a file using Ansible Vault
ansible-vault decrypt file.ymlDecrypt an encrypted file using Ansible Vault
ansible-vault rekey file.ymlChange the password for an encrypted file
ansible-vault edit file.ymlEdit an encrypted file using Ansible Vault
ansible-lint playbook.ymlLint an Ansible playbook for best practices
ansible-doc -lList all available modules
ansible-doc module-nameDisplay documentation for a specific module
ansible-playbook playbook.yml --start-at-task='task-name'Start executing a playbook from a specific task
ansible-playbook playbook.yml --tags 'tag-name'Run only tasks with a specific tag
ansible-playbook playbook.yml --skip-tags 'tag-name'Skip tasks with a specific tag
OpenTofu CLI
opentofu --versionDisplay the OpenTofu version
opentofu initInitialize a new or existing OpenTofu working directory
opentofu validateValidate the configuration files
opentofu planCreate an execution plan
opentofu applyApply the changes required to reach the desired state of the configuration
opentofu destroyDestroy all the resources managed by OpenTofu
opentofu showShow the current state or plan
opentofu fmtFormat OpenTofu configuration files to a canonical format
opentofu state listList all resources in the state file
opentofu state show resource-nameShow details of a resource in the state file
opentofu taint resource-nameMark a resource for recreation during the next apply
opentofu untaint resource-nameMark a resource as not needing recreation
opentofu import resource-name idImport existing infrastructure into OpenTofu
opentofu outputDisplay the output values from the OpenTofu state
opentofu workspace listList all OpenTofu workspaces
opentofu workspace new workspace-nameCreate a new workspace
opentofu workspace select workspace-nameSelect an existing workspace
opentofu workspace delete workspace-nameDelete a workspace
opentofu plan -out=plan.tfplanCreate an execution plan and save it to a file
opentofu apply plan.tfplanApply a previously created execution plan
opentofu validate -jsonValidate configuration files and output results in JSON format
opentofu graphGenerate a visual representation of the dependency graph
opentofu consoleStart an interactive console for OpenTofu expressions
Terragrunt CLI
terragrunt --versionDisplay the Terragrunt version
terragrunt initInitialize a Terragrunt working directory, including Terraform modules
terragrunt validateValidate Terragrunt and Terraform configuration files
terragrunt planCreate an execution plan for Terraform using Terragrunt
terragrunt applyApply the changes required to reach the desired state of the configuration
terragrunt destroyDestroy all resources managed by Terraform using Terragrunt
terragrunt showShow the current state or plan
terragrunt outputDisplay the output values from the Terraform state
terragrunt plan-allCreate execution plans for all modules defined in Terragrunt configurations
terragrunt apply-allApply the changes required to reach the desired state of all modules
terragrunt destroy-allDestroy all resources managed by Terraform across all modules
terragrunt refreshUpdate the state with the latest information from the provider
terragrunt graphGenerate a visual representation of the dependency graph for Terraform resources
terragrunt validate-allValidate all Terragrunt and Terraform configurations
terragrunt getDownload and update Terraform modules
terragrunt run-all commandRun a specified Terraform command (e.g., apply, plan) across all modules
terragrunt workspace listList all Terragrunt workspaces
terragrunt workspace new workspace-nameCreate a new workspace
terragrunt workspace select workspace-nameSelect an existing workspace
terragrunt workspace delete workspace-nameDelete a workspace