Ultimate DevOps: 150 Commands & Code
DataScienceMLesson: The Ultimate DevOps Command Reference (150 Examples)
#DevOps #Linux #Git #Docker #Kubernetes #Ansible #Terraform #CICD #AWS #Cloud
---
What is DevOps?
DevOps is a set of practices, cultural philosophies, and tools that combines software development (Dev) and IT operations (Ops). It aims to shorten the systems development life cycle and provide continuous delivery with high software quality. Key principles include automation, collaboration, rapid feedback, and iterative improvement.
Where is DevOps Used?
• Continuous Integration/Continuous Delivery (CI/CD): Automating the build, test, and deployment pipeline.
• Infrastructure as Code (IaC): Managing and provisioning infrastructure through code.
• Configuration Management: Ensuring consistency of system configurations.
• Monitoring and Logging: Observing application and infrastructure performance to ensure reliability.
• Cloud-Native Applications: Building and running scalable applications in modern cloud environments.
Alternatives to DevOps
DevOps is a methodology. Its alternatives are other development methodologies:
• Waterfall Model: A traditional, linear, and sequential approach.
• Agile: An iterative approach focusing on collaboration, from which DevOps evolved.
• Site Reliability Engineering (SRE): A discipline that applies software engineering principles to infrastructure and operations problems, often considered a specific implementation of DevOps.
---
Category 1: Linux/Shell Commands (The Foundation)
#1: ls - List Directory Contents
Shows files and directories. -la shows all files in a long list format.
ls -la#2: cd - Change Directory
Navigates into a different directory.
cd /var/log/nginx#3: pwd - Print Working Directory
Shows the full path of your current directory.
pwd#4: grep - Search Text
Searches for a text pattern in files. -i for case-insensitive.
grep -i "error" server.log#5: chmod - Change Permissions
Changes file access permissions. +x makes a file executable.
chmod +x deploy.sh#6: chown - Change Ownership
Changes the user and group owner of a file.
sudo chown www-data:www-data /var/www/html/index.html#7: curl - Transfer Data
Transfers data from or to a server. Great for testing APIs.
curl -X GET https://api.github.com/users/torvalds#8: wget - Download Files
A non-interactive tool for downloading files from the web.
wget https://releases.ubuntu.com/22.04.1/ubuntu-22.04.1-desktop-amd64.iso#9: tail - Output Last Part of Files
Shows the last few lines of a file. -f follows the file for real-time updates.
tail -n 100 -f /var/log/syslog#10: head - Output First Part of Files
Shows the first few lines of a file.
head -n 20 access.log#11: df - Report Disk Space Usage
Displays available disk space. -h makes it human-readable.
df -h#12: du - Estimate File Space Usage
Shows disk usage of files. -sh for a summarized, human-readable total.
du -sh /var/lib/docker#13: ps - Report Current Processes
Lists running processes. aux shows all processes for all users.
ps aux | grep 'java'#14: top - Display Linux Processes
Provides a real-time, dynamic view of running system processes.
top#15: kill - Terminate a Process
Sends a signal to a process, usually to terminate it.
kill 12345#16: ssh - Secure Shell
Connects securely to a remote machine.
ssh dev-user@192.168.1.100#17: scp - Secure Copy
Copies files between hosts on a network.
scp ./local-file.zip user@remote-server:/remote/dir/#18: tar - Archive Utility
Creates or extracts archive files. czvf creates a gzipped archive.
tar -czvf backup.tar.gz /home/user/app#19: unzip - Decompress ZIP files
Extracts files from a ZIP archive.
unzip application.zip#20: find - Search for Files
Searches for files in a directory hierarchy.
find /etc -name "*.conf"#21: awk - Pattern Scanning and Processing
A versatile programming language for working on files. This prints the first column.
awk '{print $1}' access.log#22: sed - Stream Editor
Performs basic text transformations on an input stream. This replaces "foo" with "bar".
sed 's/foo/bar/g' config.txt#23: cat - Concatenate and Display Files
Reads files and writes their content to standard output.
cat /etc/os-release#24: touch - Create an Empty File
Creates an empty file or updates the timestamp of an existing one.
touch /tmp/new-file.txt#25: mkdir - Create Directories
Creates new directories. -p creates parent directories as needed.
mkdir -p /opt/app/config#26: mv - Move or Rename Files
Moves or renames files and directories.
mv old-name.txt new-name.txt#27: cp - Copy Files
Copies files and directories. -r for recursive copy.
cp -r /source/dir /destination/dir#28: rm - Remove Files
Deletes files. -rf forces removal of directories and their contents.
rm -rf /tmp/temp_data#29: history - Command History
Displays a list of previously executed commands.
history | grep docker#30: ping - Check Network Connectivity
Sends ICMP ECHO_REQUEST packets to network hosts.
ping google.com#31: netstat - Network Statistics
Shows network connections, routing tables, etc. -tulpn is a common combination.
netstat -tulpn#32: nslookup - Query DNS
Queries Internet domain name servers.
nslookup github.com#33: whoami - Print Current User
Displays the username of the current user.
whoami---
Category 2: Git (Version Control)
#34: git clone - Clone a Repository
Creates a local copy of a remote repository.
git clone git@github.com:user/repository.git#35: git status - Check Repository Status
Shows the status of changes as untracked, modified, or staged.
git status#36: git add - Stage Changes
Adds file changes to the staging area for the next commit.
git add .#37: git commit - Commit Changes
Saves the staged changes to the local repository.
git commit -m "feat: Add user authentication module"#38: git push - Push to Remote
Uploads local commits to the remote repository.
git push origin main#39: git pull - Pull from Remote
Fetches and merges changes from the remote to your local branch.
git pull origin main#40: git branch - Manage Branches
Lists, creates, or deletes branches. -a lists all branches (local and remote).
git branch -a#41: git checkout - Switch Branches
Switches to a different branch. -b creates a new branch before switching.
git checkout -b feature/new-api#42: git merge - Merge Branches
Joins two or more development histories together.
git merge feature/new-api#43: git log - View Commit History
Shows the commit logs.
git log --oneline --graph --decorate#44: git diff - Show Changes
Shows changes between commits, commit and working tree, etc.
git diff HEAD#45: git remote - Manage Remotes
Manages the set of tracked repositories. -v shows URLs.
git remote -v#46: git fetch - Fetch from Remote
Downloads objects and refs from another repository without merging.
git fetch origin#47: git stash - Stash Changes
Temporarily shelves (stashes) changes you've made to your working copy.
git stash#48: git tag - Manage Tags
Creates, lists, deletes, or verifies a tag object signed with GPG.
git tag -a v1.0.0 -m "Release version 1.0.0"#49: git rebase - Reapply Commits
Reapplies commits on top of another base tip, often used for a cleaner history.
git rebase main#50: git reset - Reset Current HEAD
Resets the current HEAD to a specified state. --hard is destructive.
git reset --hard HEAD~1---
Category 3: Docker (Containerization)
#51: docker build - Build an Image
Builds a Docker image from a Dockerfile.
docker build -t my-app:latest .#52: docker run - Run a Container
Creates and starts a container from an image.
docker run -d -p 8080:80 --name web-server nginx#53: docker ps - List Containers
Shows running containers. -a shows all (including stopped).
docker ps -a#54: docker stop - Stop a Container
Stops one or more running containers.
docker stop web-server#55: docker start - Start a Container
Starts one or more stopped containers.
docker start web-server#56: docker rm - Remove a Container
Removes one or more containers.
docker rm web-server#57: docker images - List Images
Shows all locally stored Docker images.
docker images#58: docker rmi - Remove an Image
Removes one or more images.
docker rmi my-app:latest#59: docker pull - Pull an Image
Downloads an image from a registry.
docker pull redis:alpine#60: docker push - Push an Image
Uploads an image to a registry.
docker push my-registry/my-app:latest#61: docker logs - Fetch Container Logs
Displays logs of a container. -f follows the log output.
docker logs -f web-server#62: docker exec - Execute a Command in a Container
Runs a command inside a running container. -it for an interactive terminal.
docker exec -it web-server /bin/bash#63: docker inspect - Get Low-Level Information
Returns detailed, low-level information on Docker objects.
docker inspect web-server#64: docker network - Manage Networks
Manages Docker networks.
docker network create my-app-net#65: docker volume - Manage Volumes
Manages Docker volumes for persistent data.
docker volume create my-app-db-data#66: docker-compose up - Create and Start Containers
Builds, (re)creates, starts, and attaches to containers for a service.
docker-compose up -d#67: docker-compose down - Stop and Remove Containers
Stops and removes containers, networks, volumes, and images created by up.
docker-compose down -v#68: docker system prune - Clean Up Docker
Removes all unused containers, networks, images (both dangling and unreferenced).
docker system prune -a -f---
Category 4: Kubernetes (Container Orchestration)
#69: kubectl get nodes - List Cluster Nodes
Shows all machines (nodes) in the cluster and their status.
kubectl get nodes#70: kubectl get pods - List Pods
Retrieves a list of all pods in the current namespace. -n for a specific namespace.
kubectl get pods -n kube-system#71: kubectl apply - Apply a Configuration
Applies a configuration from a YAML file to a resource.
kubectl apply -f deployment.yaml#72: kubectl delete - Delete Resources
Deletes resources from a file or by name.
kubectl delete -f service.yaml#73: kubectl describe - Get Detailed State
Shows the detailed state of a resource, great for troubleshooting.
kubectl describe pod my-app-pod-xyz#74: kubectl logs - View Pod Logs
Prints the logs for a container in a pod. -f to stream.
kubectl logs -f my-app-pod-xyz#75: kubectl exec - Execute a Command in a Pod
Executes a command on a container in a pod.
kubectl exec -it my-app-pod-xyz -- /bin/sh#76: kubectl get services - List Services
Lists all services in the current namespace.
kubectl get services#77: kubectl get deployments - List Deployments
Lists all deployments in the current namespace.
kubectl get deployments#78: kubectl rollout status - Check Deployment Status
Watches the status of a deployment until it's complete.
kubectl rollout status deployment/my-app-deployment#79: kubectl rollout history - View Deployment History
Shows the revision history of a deployment.
kubectl rollout history deployment/my-app-deployment#80: kubectl rollout undo - Revert a Deployment
Rolls back a deployment to a previous revision.
kubectl rollout undo deployment/my-app-deployment#81: kubectl scale - Scale a Deployment
Sets a new size for a Deployment, ReplicaSet, or Replication Controller.
kubectl scale deployment my-app-deployment --replicas=5#82: kubectl config get-contexts - List Contexts
Displays a list of available cluster contexts.
kubectl config get-contexts#83: kubectl config use-context - Switch Contexts
Switches the active context to a different cluster.
kubectl config use-context docker-desktop#84: kubectl get configmap - List ConfigMaps
Lists configuration maps used for storing non-confidential data.
kubectl get configmap#85: kubectl get secrets - List Secrets
Lists secrets used for storing sensitive data.
kubectl get secrets#86: kubectl top pod - View Pod Resource Usage
Displays CPU and memory usage for pods.
kubectl top pod#87: kubectl get namespace - List Namespaces
Lists all namespaces in the cluster.
kubectl get namespace#88: kubectl port-forward - Forward a Local Port
Forwards one or more local ports to a pod for debugging.
kubectl port-forward svc/my-service 8080:80---
Category 5: Ansible (Configuration Management)
#89: ansible - Ad-hoc Command
Runs a single command on a group of hosts. This pings web servers.
ansible webservers -m ping#90: ansible-playbook - Run a Playbook
Executes an Ansible Playbook, a file with a series of automated tasks.
ansible-playbook deploy-app.yml --check#91: ansible-inventory - Manage Inventory
Displays the inventory of hosts Ansible knows about.
ansible-inventory --list -y#92: ansible-vault - Manage Encrypted Files
Manages encrypted files for sensitive data.
ansible-vault encrypt secrets.yml#93: ansible-galaxy - Manage Roles
Manages Ansible Roles from Ansible Galaxy or other sources.
ansible-galaxy install geerlingguy.nginx#94: ansible --version - Check Version
Displays the Ansible version.
ansible --version#95: ansible-doc - Module Documentation
Shows documentation for Ansible modules.
ansible-doc -s user---
Category 6: Terraform (Infrastructure as Code)
#96: terraform init - Initialize a Directory
Initializes a directory with Terraform config files, downloading providers.
terraform init#97: terraform plan - Create an Execution Plan
Shows what actions Terraform will take to modify infrastructure.
terraform plan#98: terraform apply - Apply Changes
Applies the changes required to reach the desired state of the configuration.
terraform apply -auto-approve#99: terraform destroy - Destroy Infrastructure
Destroys all remote objects managed by the configuration.
terraform destroy#100: terraform validate - Validate Configuration
Checks if the configuration files are syntactically valid.
terraform validate#101: terraform fmt - Format Code
Rewrites configuration files to a canonical format and style.
terraform fmt#102: terraform state list - List Resources
Lists all resources being managed in the current state file.
terraform state list#103: terraform state show - Show a Resource
Shows the attributes of a single resource in the state.
terraform state show aws_instance.web#104: terraform workspace - Manage Workspaces
Manages workspaces for different environments (e.g., dev, staging, prod).
terraform workspace new production#105: terraform output - Read an Output Variable
Reads and displays an output variable from your state file.
terraform output instance_ip_addr---
Category 7: CI/CD (GitHub CLI examples)
#106: gh repo clone - Clone a GitHub Repo
Clones a repository from GitHub.
gh repo clone cli/cli#107: gh pr create - Create a Pull Request
Creates a pull request on GitHub.
gh pr create --title "My New Feature" --body "Details here."#108: gh pr list - List Pull Requests
Lists pull requests in the repository.
gh pr list#109: gh pr checkout - Check Out a PR
Checks out a pull request locally for review.
gh pr checkout 123#110: gh workflow list - List Workflows
Lists the GitHub Actions workflows in the repository.
gh workflow list#111: gh workflow run - Run a Workflow
Triggers a manual workflow run.
gh workflow run deploy.yml#112: gh run list - List Workflow Runs
Shows a list of recent workflow runs.
gh run list#113: gh run watch - Watch a Run
Watches a workflow run in real-time until it completes.
gh run watch <run_id>---
Category 8: AWS CLI (Cloud Management)
#114: aws configure - Configure CLI
Configures your AWS credentials and default region.
aws configure#115: aws s3 ls - List S3 Buckets/Objects
Lists S3 buckets or objects within a bucket.
aws s3 ls s3://my-app-backups#116: aws s3 cp - Copy Files to/from S3
Copies a local file or S3 object. --recursive for directories.
aws s3 cp ./build s3://my-app-frontend/ --recursive#117: aws s3 sync - Sync Directories with S3
Syncs a directory with an S3 bucket, only copying new/updated files.
aws s3 sync . s3://my-config-bucket#118: aws ec2 describe-instances - Describe EC2 Instances
Describes one or more EC2 instances.
aws ec2 describe-instances --query "Reservations[*].Instances[*].PublicIpAddress"#119: aws ec2 run-instances - Launch an EC2 Instance
Launches a new EC2 instance.
aws ec2 run-instances --image-id ami-0abcdef1234567890 --count 1 --instance-type t2.micro#120: aws ec2 stop-instances - Stop EC2 Instances
Stops one or more running EC2 instances.
aws ec2 stop-instances --instance-ids i-1234567890abcdef0#121: aws iam list-users - List IAM Users
Lists the IAM users in your AWS account.
aws iam list-users#122: aws lambda list-functions - List Lambda Functions
Lists all Lambda functions in your account.
aws lambda list-functions#123: aws cloudformation deploy - Deploy a Stack
Deploys a CloudFormation stack.
aws cloudformation deploy --template-file template.yml --stack-name my-app-stack#124: aws ecr get-login-password - Get ECR Password
Retrieves an authentication token for the Amazon ECR registry.
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <aws_account_id>.dkr.ecr.us-east-1.amazonaws.com#125: aws sts get-caller-identity - Get Current Identity
Returns details about the IAM user or role whose credentials are being used.
aws sts get-caller-identity---
Category 9: Bonus Commands & Advanced Usage
#126: xargs - Build and Execute Commands
Builds and executes command lines from standard input.
find . -name "*.tmp" | xargs rm#127: jq - Command-line JSON Processor
A lightweight and flexible command-line JSON processor.
curl 'https://api.github.com/users/octocat' | jq '.name'#128: systemctl status - Check Service Status
Queries the status of a systemd service.
sudo systemctl status docker.service#129: journalctl - Query the Systemd Journal
Views logs collected by systemd. -u for a specific unit/service.
journalctl -u nginx.service -f#130: kubectl create namespace - Create Namespace
Creates a new namespace for resource isolation.
kubectl create namespace staging#131: docker buildx - Extended Build Capabilities
Builds multi-platform images.
docker buildx build --platform linux/amd64,linux/arm64 -t my-app:multi .#132: helm install - Deploy a Helm Chart
Deploys a chart to a Kubernetes cluster.
helm install stable/mysql --generate-name#133: helm list - List Helm Releases
Lists all of the releases for a specified namespace.
helm list#134: git clean - Remove Untracked Files
Removes untracked files from the working tree. -fd forces directory removal.
git clean -fd#135: ssh-keygen - Generate SSH Keys
Generates a new SSH key pair for authentication.
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"#136: lsof - List Open Files
Lists information about files opened by processes. -i to see network connections.
lsof -i :80#137: nc - Netcat
A versatile networking utility for reading from/writing to network connections.
nc -zv 192.168.1.101 22#138: dig - DNS Lookup Utility
A flexible tool for interrogating DNS name servers.
dig +short my-domain.com#139: watch - Execute a Program Periodically
Runs a command repeatedly, displaying its output.
watch -n 2 'kubectl get pods'#140: base64 - Encode/Decode Base64
Encodes or decodes data in Base64 format, often used for Kubernetes secrets.
echo -n 'my-secret-password' | base64#141: terraform import - Import Existing Infrastructure
Imports existing infrastructure into your Terraform state.
terraform import aws_s3_bucket.my_bucket my-existing-bucket-name#142: ansible-vault edit - Edit Encrypted File
Edits an Ansible Vault encrypted file in-place.
ansible-vault edit vars/secrets.yml#143: kubectl autoscale - Autoscale a Deployment
Creates a Horizontal Pod Autoscaler to automatically scale a deployment.
kubectl autoscale deployment my-app --cpu-percent=80 --min=3 --max=10#144: docker-compose logs - View Compose Logs
Displays log output from services managed by Docker Compose.
docker-compose logs -f web#145: git cherry-pick - Apply a Specific Commit
Applies a single, specific commit from another branch.
git cherry-pick a1b2c3d4#146: export - Set Environment Variable
Sets an environment variable for the current shell session.
export AWS_REGION="us-east-1"#147: source - Execute Commands from a File
Reads and executes commands from a file in the current shell.
source ~/.bashrc#148: crontab - Schedule Commands
Manages cron jobs, which are time-based job schedulers. -e to edit.
crontab -e#149: htop - Interactive Process Viewer
An interactive process viewer, an enhanced version of top.
htop#150: alias - Create Command Shortcuts
Creates a shortcut (alias) for a longer command.
alias k='kubectl'