0% found this document useful (0 votes)
38 views

DevOps Cheat Sheet

Uploaded by

Umesh Sonar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

DevOps Cheat Sheet

Uploaded by

Umesh Sonar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Eric Enning @ https://www.linkedin.

com/in/eebk37/

DevOps CheatSheet
Docker Cheat Sheet Helm Cheat Sheet
Kubernetes Cheat Sheet Terraform Cheat Sheet
Linux Cheat Sheet Git Cheat Sheet
AWS Cheat Sheet HTTP Cheat Sheet

Eric Enning @ https://www.linkedin.com/in/eebk37/


AWS Cheat Sheet
Installation Identity and Access Management (IAM)
Command Description
See https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
aws iam list-users List users
For autocompletion see https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-completion.html.
aws iam list-groups List groups
aws iam list-roles List roles
Global flags
aws iam list-policies List policies
Flag Description
aws iam create-user --user-name <name> Create a user
--profile <name> Run a command using the specified profile
aws iam create-group --group-name
--output <style> Format output as (json/text/table/yaml) Create a group
<name>
--help Show help
aws iam create-role --role-name <name>
Create a role
--endpoint-url <url> Override default API endpoint --assume-role-policy-document <policy>

--region Override default region aws iam create-policy --policy-name


Create a policy
<name> --policy-document <policy>
--version Show version of AWS CLI

Elastic Compute Cloud (EC2)


Configuration
Command Description
Command Description
aws ec2 describe-instances List instances
aws configure Configure AWS
aws ec2 run-instances --image-id <id>
aws configure sso Configure AWS IAM Identity Center credentials Create an instance
--instance-type <type>
aws configure list Show current configuration data aws ec2 terminate-instances
Terminate an instance
--instance-ids <id>
aws configure set <key> <value> Set a configuration value
aws ec2 start-instances --instance-ids
aws configure get <key> Show a configuration value Start an instance
<id>
aws ec2 stop-instances --instance-ids
Profiles <id>
Stop an instance

Command Description
aws configure --profile <name> Create a new profile Elastic Kubernetes Service (EKS)
aws configure list-profiles Show available profiles Command Description
aws eks list-clusters List clusters
Account information aws eks describe-cluster --name <name> Describe a cluster
Command Description aws eks create-cluster --name <name> Create a cluster
aws sts get-caller-identity Retrieve account information aws eks delete-cluster --name <name> Delete a cluster
Relational Database Service (RDS)
Command Description
aws rds describe-db-clusters List clusters
aws rds describe-db-instances List instances
aws rds create-db-cluster-snapshot Create a snapshot of a cluster

Simple Storage Service (S3)


Command Description
aws s3 ls List buckets
aws s3 ls s3://<bucket> List objects in a bucket
aws s3 mb s3://<bucket> Create a bucket
aws s3 rb s3://<bucket> Delete a bucket
aws s3 cp <src> <dest> Copy a file from/to S3
aws s3 rm s3://<bucket>/<object> Delete an object
aws s3 sync s3://bucket <dir> Sync a bucket to a local directory
aws s3 sync <dir> s3://bucket Sync a local directory to an S3 bucket

Other commands
Command Description
aws --version Show version
aws help Show help including all available commands
aws <command> help Show help for a specific command
Docker Cheat Sheet

Installation Container registry commands


Command Description
Install Docker Engine (https://docs.docker.com/engine/install/, Linux only) or Docker Desktop
(https://docs.docker.com/desktop/, Linux, macOS and Windows). docker login Login to Docker Hub
docker login <server> Login to another container registry
Container commands docker logout Logout of Docker Hub
Command Description
docker logout <server> Logout of another container registry
docker run <image> Create and run a new container
docker push <image> Upload an image to a registry
docker run -p 8080:80 <image> Publish container port 80 to host port 8080
docker pull <image> Download an image from a registry
docker run -d <image> Run a container in the background
docker search <image> Search Docker Hub for images
docker run -v <host>:<container>
Mount a host directory to a container
<image>
System commands
docker ps List currently running containers
Command Description
docker ps --all List all containers (running or stopped)
docker system df Show Docker disk usage
docker logs <container_name> Fetch the logs of a container
docker system prune Remove unused data
docker logs -f <container_name> Fetch and follow the logs of a container
docker system prune -a Remove all unused data
docker stop <container_name> Stop a running container
docker start <container_name> Start a stopped container
Docker Compose
docker rm <container_name> Remove a container
Command Description
docker compose up Create and start containers
Executing commands in a container
docker compose up -d Create and start containers in background
Command Description
docker compose up --build Rebuild images before starting containers
docker exec <container_name> <command> Execute a command in a running container
docker compose stop Stop services
docker exec -it <container_name> bash Open a shell in a running container
docker compose down Stop and remove containers and networks
docker compose ps List running containers
Image commands
docker compose logs View the logs of all containers
Command Description
docker compose logs <service> View the logs of a specific service
Build a new image from the Dockerfile in the current
docker build -t <image> .
directory and tag it docker compose logs -f View and follow the logs
docker images List local images docker compose pull Pull the latest images
docker rmi <image> Remove an image docker compose build Build or rebuild services
docker compose build --pull Pull latest images before building
Dockerfile instructions Docker Compose file reference
Instruction Description Key Description
FROM <image> Set the base image name Set the name of the project
FROM <image> AS <name> Set the base image and name the build stage services A list of services defined in the file
RUN <command> Execute a command as part of the build process services.<name>.image Set the image to use or build
RUN ["exec", "param1", "param2"] Execute a command as part of the build process services.<name>.build Build context and options
CMD ["exec", "param1", "param2"] Execute a command when the container starts services.<name>.build.context Build context (default is the current directory)
ENTRYPOINT ["exec", "param1"] Configure the container to run as an executable services.<name>.build.dockerfile Dockerfile to use (default is Dockerfile)
ENV <key>=<value> Set an environment variable services.<name>.build.target Build stage to use
EXPOSE <port> Expose a port services.<name>.build.args Build arguments
COPY <src> <dest> Copy files from source to destination services.<name>.command Override the default command for the container
COPY --from=<name> <src> <dest> Copy files from a build stage to destination services.<name>.entrypoint Override the default entrypoint for the container
WORKDIR <path> Set the working directory services.<name>.volumes Mount volumes in the container
VOLUME <path> Create a mount point services.<name>.ports Publish container ports to the host
USER <user> Set the user services.<name>.environment Set environment variables in the container
ARG <name> Define a build argument services.<name>.restart Restart policy (no/always/on-failure/unless-stopped)
ARG <name>=<default> Define a build argument with a default value services.<name>.scale Set the number of containers to run
LABEL <key>=<value> Set a metadata label services.<name>.networks List of networks to connect the container to
HEALTHCHECK <command> Set a healthcheck command services.<name>.depends_on List of services to start before this service
services.<name>.labels Set metadata labels for the container
See https://docs.docker.com/engine/reference/builder/ for the full Dockerfile reference.
networks A list of networks defined in the file

Example compose.yaml networks.<name>.driver Set the network driver


networks.<name>.external Don't create the network, use an existing one
Note: this file used to be called docker-compose.yaml, but now compose.yaml is preferred.
volumes A list of volumes defined in the file
services:
volumes.<name>.name Set the name of the volume
service1:
image: <image> volumes.<name>.driver Set the volume driver
build: .
configs A list of configs defined in the file
volumes:
- .:/code:ro secrets A list of secrets defined in the file
ports:
- "8000:80" See https://docs.docker.com/compose/compose-file/ for the full Docker Compose file reference.
environment:
KEY: value
Git Cheat Sheet
Workflow Local changes (cont.) Collaboration
Command Description Command Description
git diff Show unstaged changes git remote -v List remote repositories
git diff --staged Show staged changes git remote add <name>
Add a new remote repository
<url>
Commit staged changes using the
git commit
default editor Download all changes from a
git fetch <remote> remote repository but don't
Commit staged changes with a integrate them
git commit -m <message> message provided on the
command line Download changes and directly
git pull <remote>
merge/integrate them
git commit --amend Amend the last commit
git pull <remote> Download changes and directly
Start a new repository git reset HEAD <file> Unstage a file <branch> merge/integrate a remote branch
Command Description git checkout -- <file> Discard local changes in a file git push <remote> Upload local changes to a remote
<branch> repository
Create a new repository in the
git init
current directory Branches git push <remote>
Delete a remote branch
--delete <branch>
git clone <url> [<dir>] Clone a remote repository Command Description
git push <remote> --tags Push tags to a remote repository
git branch List local branches
History git branch -r List remote branches
Command Description
Stashing
git branch <branch> Create a new branch
Command Description
git log Show commit logs
git checkout <branch> Switch to a branch
Stash the changes in a dirty
Show commit logs with one line git stash
git log --oneline Create a new branch and switch working directory away
per commit git checkout -b <branch>
to it
git stash list List all stashes
Show the changes of the last
git show Merge a branch into the active
commit git merge <branch> git stash pop Apply the last stash and delete it
branch
Summarize git log output by Apply the last stash but don't
git shortlog git branch -d <branch> Delete a branch git stash apply
author delete it
Show who changed which line in a git stash drop Delete the last stash
git blame <file>
file Tags
git stash clear Delete all stashes
Command Description

Local changes git tag List tags


Writing good commit messages
Command Description git tag <tag> Create a tag
1. Separate subject from body with a blank line
List which files are staged, git tag -a <tag> Create an annotated tag
git status 2. Limit the subject line to 50 characters
unstaged, and untracked
git tag -s <tag> Create a GPG-signed tag 3. Capitalize the subject line
git add <file> Add a file to the staging area 4. Do not end the subject line with a period
git tag -d <tag> Delete a tag
Interactively choose hunks of a 5. Use the imperative mood in the subject line
git add -p git show <tag> Show the tag data 6. Wrap the body at 72 characters
file to add to the staging area
7. Use the body to explain what and why vs. how
Helm Cheat Sheet

Helm Listing releases


Command Description
Helm is the package manager for Kubernetes. See https://helm.sh/docs/intro/install/ for installation
instructions. helm list List all releases in the current namespace
helm list --all-namespaces List all releases in all namespaces
Global flags helm list -l <label>=<value> List releases with a specific label
Flag Description
helm list --date List releases sorted by date
--kube-context <name> Name of the Kubernetes context to use
helm list List releases that are in a pending/failed/uninstalled
--namespace <name> Namespace to use for this operation --(pending|failed|uninstalled) state
helm status <name> Show the status of a release
Repository management
Command Description Managing releases
helm repo add <name> <url> Add a repository Command Description

helm repo list List all added repositories helm upgrade <name> <chart> Upgrade a release

helm repo update Update the local cache of available charts helm upgrade <name> <chart> --atomic Upgrade a release atomically

helm repo remove <name> Remove a repository helm upgrade <name> <chart>
Upgrade a release and update dependencies
--dependency-update
helm search repo List all charts in the repositories
helm upgrade <name> <chart> --version
helm search repo <keyword> Search for a chart in the repositories Upgrade a release to a specific version
<version>
helm upgrade <name> <chart> --set
Upgrade a release with specific values
Installing Helm charts <key>=<value>

Command Description helm rollback <release> <revision> Rollback a release to a previous revision
helm install <name> <chart> Install a chart with a name
helm install <chart> --generate-name Install a chart, auto-generating a name Developing charts
helm install <name> <chart> --namespace Command Description
Install a chart in a specific namespace
<namespace>
helm create <name> Create a new chart
helm install <name> <chart> --set
Install a chart with specific values
<key>=<value> helm package <chart-path> Package a chart directory into a chart file
helm install <name> <chart> --values <file> Install a chart using a values file
helm lint <chart> Lint a chart
helm install <name> <chart> --dry-run --debug Run a test installation to validate the chart
helm show all <chart> Inspect a chart and list all resources
helm install <name> <chart> --verify Verify the package before installing
helm show values <chart> Inspect a chart and show default values
helm install <name> <chart>
Update dependencies before installing
--dependency-update helm template <name> <chart> Render templates locally
helm uninstall <name> Uninstall a release
helm template <name> <chart> --set
Render templates locally and override values
helm uninstall <name> --keep-history Uninstall a release, keeping the history <key>=<value>
HTTP Cheat Sheet
Example Request & Response Request Headers Status Codes
Header Description
GET /hello.txt HTTP/1.1 A detailed list of status codes can be found in RFC 9110.
Host: www.example.com Referer: <url> The referring web page URL
User-Agent: Mozilla/5.0
Accept-Language: en, nl User-Agent: <ua>
Information about the client Status Codes: Informational
making the request
Code Description
Authorization: <scheme> Authenticate using the specified
<params> scheme and credentials The server has received the
HTTP/1.1 200 OK 100 Continue request headers and the client
Date: Mon, 27 Jul 2020 12:28:53 GMT The media types that the client should proceed
Accept: <media-types>
Server: Apache/2.2.22 can understand
The server will switch protocols to
Content-Length: 12 Accept-Encoding: The encoding algorithms the 101 Switching Protocols those defined by the response's
Content-Type: text/plain <algorithms> client understands Upgrade header field

Hello World! The languages that the client can


Accept-Language: <langs>
understand
Status Codes: Success
Methods Code Description
Response Headers
Method Description 200 OK The request has succeeded
Header Description
Transfer a current representation 201 Created A new resource has been created
GET (safe, idempotent) The URL of the new resource or
of the resource Location: <url>
redirect target The request was accepted but
Same as GET, but without 202 Accepted processing has not been
HEAD (safe, idempotent) The methods supported by the
transferring content Allow: <methods> completed
resource
Process the content of the The response content has been
POST Information about the server 203 Non-Authoritative Information
request Server: <name> modified by a proxy
software
Update the resource with the The request was fulfilled but no
PUT (idempotent) Retry-After: <s> Time to wait before a new request 204 No Content
content of the request content is returned

Remove all current The age of the cached response Request fulfilled; the user agent
DELETE (idempotent) Age: <s> 205 Reset Content
representations of the resource (in sec) should reset the view

CONNECT Establish a tunnel to the server Cache-Control: Directives for caching The server has fulfilled a partial
<directives> mechanisms 206 Partial Content
GET request
Describe the communication
OPTIONS (safe, idempotent) Date/time after which the
options for the target resource Expires: <date>
response expires
Perform a message loop-back test Status Codes: Redirection
TRACE (safe, idempotent)
along the path to the resource Code Description
See RFC 9111 for detailed information about caching.

"Safe" methods are read-only and should not change the server The requested resource
300 Multiple Choices corresponds to any one of a set of
state. "Idempotent" methods can be called multiple times without
representations
different outcomes. See RFC 9110 for detailed information about
each method. The requested resource has been
301 Moved Permanently
assigned a new permanent URI
The requested resource resides
302 Found
temporarily under a different URI
Status Codes: Redirection (cont.) Status Codes: Client Error (cont.)
Code Description Code Description
A different resource can provide The requested media type is not
303 See Other 415 Unsupported Media Type
an indirect reponse supported
The resource has not been The request Range header is not
304 Not Modified 416 Range Not Satisfiable
modified since the last request satisfiable
Temporary redirect; client must The server cannot meet the
307 Temporary Redirect 417 Expectation Failed
not change the request method Expect header
Permanent redirect; client must The request was directed at a
308 Permanent Redirect
not change the request method 421 Misdirected Request server that is not able to produce
a response for this request
The server understands the
Status Codes: Client Error 422 Unprocessable Content content type but cannot process
Code Description the content
The server cannot / will not The client should switch to a
426 Upgrade Required
400 Bad Request process the request due to a different protocol
client error
The request requires user
401 Unauthorized
authentication
Status Codes: Server Error
Code Description
The server understood but refuses
403 Forbidden
the request The server encountered an
500 Internal Server Error
unexpected error
No resource was found for the
404 Not Found
request URI The server does not support the
501 Not Implemented functionality required to fulfill the
The method is not allowed for the request
405 Method Not Allowed
resource
The upstream server returned an
No representation matches the 502 Bad Gateway
406 Not Acceptable invalid response
Accept-* headers
The server is currently unable to
407 Proxy Authentication The client must authenticate with 503 Service Unavailable
handle the request
Required the proxy server
The upstream server did not
The server timed out waiting for 504 Gateway Timeout
408 Request Timeout respond in time
the request
The server does not support the
The request conflicts with the 505 HTTP Version Not Supported
409 Conflict HTTP version
current resource state
The requested resource is
410 Gone
permanently unavailable
The server requires a
411 Length Required
Content-Length header
One or more conditions evaluated
412 Precondition Failed
to false
413 Content Too Large The request content is too large
414 URI Too Long The target URI was too long
Kubernetes Cheat Sheet

Installation Apply configuration manifests


Command Description
Install the kubectl command line tool to interact with the Kubernetes API:
https://kubernetes.io/docs/tasks/tools/#kubectl kubectl apply -f <file> Apply a manifest from a file
kubectl apply -f <dir> Apply all manifests in a directory
Enable autocompletion in bash:
kubectl apply -k <dir> Apply resources from a kustomize directory
composer completion bash | sudo tee /etc/bash_completion.d/kubectl

Create resources manually


Global flags
Command Description
Flag Description
kubectl run <name> --image=<image> Start a pod
--namespace <namespace> The name of the namespace to use
kubectl create deployment <name>
--context <context> The name of the context to use Create a deployment
--image=<image>
--help Show information about a given command kubectl expose pod <pod> --port=<port> Create a service for an existing pod
kubectl expose deployment <name>
Create a service for an existing deployment
Context and configuration --port=<port>
Command Description kubectl create ingress <name>
Create an ingress that routes traffic to a service
--rule=<host/path=svc:port>
kubectl config get-contexts List all contexts
kubectl create job <name>
kubectl config current-context Display the current context Create a job
--image=<image>
kubectl config use-context <context> Switch to another context kubectl create job <name>
Create a job from a cronjob
kubectl config delete-context <context> Delete the specified context from the kubeconfig --from=cronjob/<name>
kubectl create cronjob <name>
Create a cronjob, using a schedule in Cron format
--image=<image> --schedule=<schedule>
Display resources
kubectl create secret generic <name>
Command Description Create a secret containing <key> and <value>
--from-literal=<key>=<value>
List all resources of this type in the current kubectl create secret docker-registry
kubectl get <resource>
namespace <name> --docker-server=<server>
Create a secret for a Docker registry
kubectl get <resource> -o wide List all resources with more details --docker-username=<username>
--docker-password=<password>
kubectl get <resource> -A List all resources of this type in all namespaces
kubectl get <resource> <name> List a particular resource
Generate YAML configuration manifests
kubectl get <resource> <name> -o yaml Print a particular resource in YAML format
Command Description
kubectl get <resource> <name> -l List resources where label <key1> contains
kubectl create deployment <name>
<key1>=<value1> <value1>
--image=<image> --dry-run=client -o Generate a deployment manifest
kubectl describe <resource> Show detailed information about a resource yaml
kubectl expose deployment <name>
Generate a service manifest for a deployment
--port=<port> --dry-run=client -o yaml
Edit resources Execute commands
Command Description Command Description
kubectl edit <resource> <name> Edit a resource in a text editor kubectl exec <pod> -- <command> Execute a command in a running pod
kubectl set image <resource> <name> kubectl exec -it <pod> -- sh Open a shell in a running pod
Update the image of a container in a pod
<container>=<image>

View logs
Set labels and annotations Command Description
Command Description
kubectl logs <pod> Print the logs for a pod
kubectl label <resource> <name>
Add a label to a resource kubectl logs -f <pod> Print the logs for a pod and keep streaming
<key>=<value>
kubectl annotate <resource> <name>
Add an annotation to a resource
<key>=<value> Resource usage
Command Description
Delete resources kubectl top node Show resource (CPU/memory) usage of nodes
Command Description kubectl top pod Show resource (CPU/memory) usage of pods
kubectl delete <resource> <name> Delete a particular resource

kubectl delete <resource> --all


Delete all resources of a particular type in the Other commands
current namespace
Command Description
kubectl delete -f <file> Delete a resource from a file
kubectl version Show the version of the client and server
kubectl api-resources Print the supported API resources on the server
Manage deployments
Command Description
kubectl rollout status deployment
Show the status of a deployment rollout
<name>
kubectl rollout history deployment
View the rollout history of a deployment
<name>
kubectl rollout undo deployment <name> Undo a previous rollout deployment
kubectl rollout restart deployment
Restart a deployment
<name>
kubectl scale deployment <name>
Scale a deployment to <n> replicas
--replicas=<n>
kubectl autoscale deployment <name> Autoscale a deployment between <n> and <n>
--min=<min> --max=<max> replicas
Linux Cheat Sheet
File Commands Directory Aliases File Permission Commands
Command Description Alias Directory Command Description
cat <file> Print file contents . Current directory chmod <mode> <file> Change file permissions
touch <file> Create file (or update timestamp) .. Parent directory Add execute permission for the
chmod u+x <file>
owner
cp <src> <dst> Copy a file ~ Home directory
Set file permissions to 644
mv <src> <dst> Move / rename a file chmod 644 <file> (read/write for owner, read for
rm <file> Remove file Link Commands group and everyone else)

head <file> Print first 10 lines of file Command Description Add write permission for the
chmod -R g+w <dir>
group recursively to a directory
tail <file> Print last 10 lines of file ln -s <target> <link> Create symbolic link
chown <owner> <file> Change file owner
Print last 10 lines and any new ln <target> <link> Create hard link
tail -f <file> Change directory owner
lines added to file readlink -f <file> Print absolute path of file chown -R <owner> <dir>
recursively
chown <owner>:<group>
Directory Commands Search Commands <file>
Change file owner and group

Command Description Command Description chgrp <group> <file> Change file group
ls List files in the current directory grep <pattern> <file...> Search for pattern in file(s)
ls <dir> List files in <dir> Search for pattern recursively in a File Permission Bits
grep -r <pattern> <dir>
ls -l List files with details directory Bit Description
ls -a List all files (including hidden) Search for pattern case- 4 Read (r)
grep -i <pattern> <file>
insensitively
ls -al List all files with details 2 Write (w)
Search for lines not matching
grep -v <pattern> <file>
Print the current/working pattern 1 Execute (x)
pwd
directory
grep -n <pattern> <file> Search and print line numbers
Change current directory to First digit represents the owner, the second digit represents the
cd <dir> Find files in <dir> with name group, and the third digit represents everyone else.
<dir> find <dir> -name <name>*
starting with <name>
cd .. Go up one directory For example, 640 means read/write for owner, read for group, and no
Find files in <dir> of type
find <dir> -type <type> permissions for everyone else.
mkdir <dir> Create directory <type>
Create directory and any missing
mkdir -p <dir>
parent directories File Permission User Types
Superuser Commands
cp -r <src> <dst> Copy a directory and its contents User Type Description
Command Description
mv <src> <dst> Move / rename a directory u Owner
sudo <cmd> Run command as superuser (root)
rmdir <dir> Remove an empty directory g Group
su Switch to superuser (root)
Remove a directory and its o Everyone else
rm -r <dir> su <user> Switch to user <user>
contents a All
System Information Commands Secure Shell (SSH) Commands IO Redirection
Command Description Command Description Command Description
df Show file system disk usage ssh-keygen Generate SSH key pair Replace contents of file with
<cmd> > <file>
output
df -h Show disk usage in MB/GB/TB ssh-add <key> Add SSH key to SSH agent
<cmd> >> <file> Append output to file
du Show disk usage per directory ssh-add -l List SSH keys in SSH agent
<cmd> < <file> Redirect input from file
du -h Show disk usage in MB/GB/TB Copy SSH key to <host> for
ssh-copy-id <user>@<host>
<user> <cmd> 2> <file> Redirect stderr to file
free Show memory usage
Connect to <host> as current <cmd> &> <file> Redirect stdout and stderr to file
free -h Show memory usage in MB/GB/TB ssh <host>
user
uptime Show uptime ssh <user>@<host> Connect to <host> as <user>
Pipe Commands
whoami Show current user Copy local file <src> to <dest>
scp <src> <host>:<dest> Command Description
uname Show system information on <host>
<cmd1> | <cmd2> Pipe stdout to next cmd
uname -a Show all system information Copy file <src> from <host> to
scp <host>:<src> <dest>
local <dest> <cmd1> |& <cmd2> Pipe stderr to next cmd

Shutdown/Reboot Commands
APT Commands (Debian/Ubuntu) Bash Shortcuts
Command Description
Command Description Shortcut Description
Power off the system after 1
shutdown apt install <pkg> Install package Ctrl + C Stop current command
minute
shutdown now Power off the system immediately apt remove <pkg> Remove package Ctrl + A Go to beginning of line

shutdown 16:30 Power off the system at 16:30 apt purge <pkg> Remove package and config files Ctrl + E Go to end of line

shutdown -c Cancel a scheduled shutdown apt update Update package list Ctrl + K Cut current line

reboot Reboot system apt upgrade Upgrade packages Ctrl + L Clear screen

poweroff Power off system apt search <term> Search for package


Directory Structure
Process Commands Other Commands Directory Description

Command Description Command Description / Root

ps List processes echo <msg> Print message to stdout /bin Binary or executable programs

ps -ef List all processes man <cmd> Display manual page for <cmd> /etc System configuration files

top Display processes in real time Display history of given /home User home directories
history
commands
kill <pid> Kill process /opt Optional or third-party software
which <cmd> Find path to executable <cmd>
pkill <name> Kill process with name /tmp Temporary files
Locate binary, source, and
whereis <cmd> /usr User programs
killall <name> Kill all processes with name manual page for <cmd>
/var Variable data
/var/log Log files
Terraform Cheat Sheet

Installation Managing state


Command Description
See https://developer.hashicorp.com/terraform/downloads for installation instructions for your platform.
Then run terraform -install-autocomplete to enable shell autocompletion. terraform show Show the current state in human-readable form
terraform show <file> Show a human-readable state or plan file
Initializing Terraform terraform show -json <file> Show a state or plan file in JSON format
Command Description
terraform state list List all resources in the state file
terraform init Prepare your working directory for other commands
terraform state show <resource> Show details about a resource
Upgrade modules/providers to the latest allowed
terraform init -upgrade terraform state mv <source> <dest> Rename a resource in the state file
versions
terraform state rm <resource> Remove a resource from the state file
terraform get Only download and install modules
terraform state replace-provider <from>
Replace provider for resources in the state
<to>
Making infrastructure changes
terraform import <resource> <remote_id> Import existing infrastructure into Terraform
Command Description
terraform state pull Pull current state and output to stdout
terraform plan Show changes required by the current configuration
terraform refresh (Deprecated) Update state to match reality
terraform plan -out=<file> Write the plan to a file to apply it later
terraform plan -target <resource> Create a plan for a specific module or resource
Tainting resources
terraform plan -replace <resource> Force the plan to replace a specific resource
Command Description
terraform plan -var '<key>=<value>' Set a value for one of the input variables
terraform taint <resource> (Deprecated) Mark a resource to be replaced
terraform plan -refresh-only Inspect resource drift without updating the state file
terraform untaint <resource> Mark a resource as no longer tainted
terraform apply Create or update infrastructure
terraform apply <file> Create or update infrastructure using a plan file Destroying infrastructure
terraform apply -target <resource> Create or update a specific resource Command Description
terraform apply -replace <resource> Force the replacement of a specific resource terraform destroy Destroy infrastructure managed by Terraform
terraform apply -auto-approve Skip interactive approval of plan before applying terraform destroy -target <resource> Destroy a specific resource

Inspecting output values Formatting and validation


Command Description Command Description
terraform output Show all output values terraform validate Check whether the configuration is valid
terraform output -json Show all output values in JSON format terraform fmt Reformat your configuration in the standard style
terraform output <name> Show a specific output value
Check whether the configuration is formatted
terraform fmt -check
terraform output -raw <name> Show a specific output value without quotes correctly, return non-zero exit code if not
Terraform Cloud / Remote Authentication Conditional Expressions
Command Description Syntax Description
terraform login Log in to Terraform Cloud If condition is true, return true, otherwise return
condition ? true : false
false
terraform login <hostname> Log in to a different host
terraform logout Log out of Terraform Cloud
Splat Expressions
terraform logout <hostname> Log out of a different host
Syntax Description
Return a list of values for the given attribute of all
Managing workspaces <RESOURCE_TYPE>.<NAME>[*].<ATTRIBUTE>
instances of a resource
Command Description
terraform workspace list List all existing workspaces Resource Meta-Arguments
terraform workspace show Show the name of the current workspace Argument Description
terraform workspace select <name> Select a different workspace depends_on Explicitly specify resource dependencies
terraform workspace new <name> Create a new workspace count Create multiple instances of a resource
terraform workspace delete <name> Delete an existing workspace Create an instance of a resource for each element in
for_each
a map or set

Other commands Specify a provider configuration block to use for this


provider
resource
Command Description
Configure the behavior of a resource over its
lifecycle
terraform providers Show the providers required for this configuration lifetime
terraform force-unlock <lock-id> Release a stuck lock
terraform console Try Terraform expressions at an interactive prompt Lifecycle Meta-Argument Attributes
terraform graph | dot -Tpng > graph.png Generate a visual graph of Terraform resources Argument Description

terraform version Show the current Terraform version Create the new resource before destroying the old
create_before_destroy
one
terraform -help Show help output for Terraform
prevent_destroy Prevent Terraform from destroying the resource
terraform -help <command> Show help output for a specific Terraform command
ignore_changes Ignore changes to specific resource attributes

Referencing Named Values


Syntax Description
<RESOURCE_TYPE>.<NAME> Reference to a managed resource
var.<NAME> Reference to an input variable
local.<NAME> Reference to a local value
module.<MODULE NAME> Reference to a child module
data.<DATA TYPE>.<NAME> Reference to a data source

You might also like