Skip to content

Instantly share code, notes, and snippets.

@mrexojo
Forked from habbdt/Git cheat sheets
Last active February 21, 2024 05:09
Show Gist options
  • Save mrexojo/260262998f7e5c3ca4b7505f82b7a25a to your computer and use it in GitHub Desktop.
Save mrexojo/260262998f7e5c3ca4b7505f82b7a25a to your computer and use it in GitHub Desktop.
CHEATS
### Markdown
https://packetlife.net/media/library/16/Markdown.pdf
### GIT
https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet
### Bash
https://devhints.io/bash.html (really nice)
### Python CheatSheet
https://perso.limsi.fr/pointal/_media/python:cours:mementopython3-english.pdf
### Python libraries for visualizing data
https://pyviz.org/tools.html
### Python: Pandas instead SQL
https://gist.github.com/serjee/b0e856e86efd28e49af287d768b990af
### Regular Expressions in Python
https://habr.com/ru/post/349860/
### Jupyter Cheatsheet
http://get.treasuredata.com/rs/714-XIJ-402/images/TD_Jupyter%20Notebook%20Cheatsheet_V1%281%29%20%281%29.pdf
### MySQL Cheat Sheet
https://gist.github.com/serjee/628fabbf1190eacf11d0e9f378270870
### PostgreSQL
http://www.postgresonline.com/downloads/special_feature/postgresql90_cheatsheet_A4.pdf
### C# Cheatsheet
https://github.com/jwill9999/C-Sharp-Cheatsheet
### Javascript Cheatsheet
https://gist.github.com/chrisbrocklesby/ad841957edce360987a8e913430a3560
### Online sequence diagram editor
https://www.websequencediagrams.com/
### Post Test Server Online
https://ptsv2.com/
docker run - run a container from an image
docker pull - pull an image from a registry
docker push - push an image to a registry
docker build - build an image from a Dockerfile
docker ps - list running containers
docker stop - stop a running container
docker start - start a stopped container
docker restart - restart a container
docker logs - show the logs of a container
docker exec - execute a command inside a running container
docker images - list available images
docker rm - remove a container
docker rmi - remove an image
docker inspect - show information about a container
docker network create - create a network for containers to communicate
docker network connect - connect a container to a network
docker network disconnect - disconnect a container from a network
docker port - show the mapped ports of a container
docker cp - copy files between a container and the host
docker commit - create a new image from a container's changes
docker login - log in to a registry
docker logout - log out of a registry
docker tag - tag an image with a new name
docker export - export the contents of a container as a tar archive
docker import - create a new image from a tar archive
docker save - save an image as a tar archive
docker load - load an image from a tar archive
docker top - show the processes running inside a container
docker stats - show resource usage statistics of containers
docker diff - show the changes made to a container's filesystem
docker events - show the events generated by Docker
docker history - show the history of an image
docker pause - pause a running container
docker unpause - unpause a paused container
docker kill - send a signal to a container to stop it abruptly
docker wait - wait for a container to exit and return its exit code
docker attach - attach to a running container's console
docker buildx - build and push multi-platform images
docker compose - manage multi-container applications with Docker Compose
docker swarm - create and manage a cluster of Docker nodes
docker volume create - create a named volume for persistent data storage
docker volume ls - list available volumes
docker volume rm - remove a named volume
docker system prune - remove all unused objects from Docker
docker system df - show the usage of Docker objects
docker system events - show the events generated by Docker on the system
docker system info - show the system-wide information about Docker
docker system inspect - show detailed information about Docker objects
docker system logs - show the system logs of Docker
docker system version - show the version of Docker installed on the system
#get network ips from network $1
docker network inspect -f '{{range .Containers}}{{println .Name .IPv4Address}}{{end}}' mibb
#Installation and Setting Parameters:
yum install git # Install git
git config --global user.name "<user_name>" # Git global conf
git config --global user.email "<email>" # Git global conf
git config --global system.name "server1.example.com" # Git global conf
git config --global core.editor vim # Set editor to be vim
git config --global core.page 'more' # Git global conf
git config --global core.excludefile ~/.gitignore_global # Ignore files - add lists of the files to be excluded
git config --list
#Basics_Repository:
#[1] Example- Basic git repo work flow
mkdir -p local_repo ; cd local_repo
git init
echo "Hello World" >> hello_world.txt
git add hello_world.txt
git commit -m "Hello World Commit"
git status
#[2] Example - Ignore by .gitignore
mkdir -p local_repo1 ; cd local_repo1
git init
echo "*.conf" >> .gitignore # Ignore all the files with "*.conf"
echo ".gitignore" >> .gitignore
cp /etc/* .
git add <add_individaully> # git add * will not work for this case
git commit
git status
#[2.1] Delete files and folders and commit changes to repo
git checkout infra2 # change to infra2 branch
rm -f Folder1/ Folder2/FolderZ/ file.txt
git add -u :/ # indicate delete files & folders on repo
git commit -m "clean: Delete PRE2 and test files" # save and comment thi step
git push -u origin infra2 # upload changes
#[2.2] Set previous commit from "master" branch to Undo changes whitout commit
git status
git fetch --all
git reset --hard origin/master
git pull
git status
# 2.3 git merge
git checkout master
git merge hotfix
# 2.4 git discard changes from current path
git checkout -- .
#[3] Example - Bad Example Cloning Local Repo
mkdir -p local_repo_original
cd local_repo_original/
git init
echo ".gitignore" >> .gitignore
echo "*.conf" >> .gitignore
cp /etc/* .
for i in `ls * | grep -v conf `; do git add $i; done
git commit -m "This is a simple commit"
git status
cp -rf local_repo_original/ local_repo_clone_01 # Synchronization with master branch or original repo will not be possible
cd local_repo_clone_01/
git status
#[4] Example - Cloning Local Repo
mkdir -p local_repo_original
cd local_repo_original/
git init
echo ".gitignore" >> .gitignore
echo "*.conf" >> .gitignore
cp /etc/* .
for i in `ls * | grep -v conf `; do git add $i; done
git commit -m "This is a simple commit"
git status
git clone local_repo_original/ local_repo_clone/
cd local_repo_clone/
git status
#[5] Example Synchronization of two repo
mkdir -p local_repo_original
cd local_repo_original/
git init
echo ".gitignore" >> .gitignore
echo "*.conf" >> .gitignore
cp /etc/* .
for i in `ls * | grep -v conf `; do git add $i; done
git commit -m "This is a simple commit"
git status
git clone local_repo_original/ local_repo_clone/
cd local_repo_clone/
touch index.html
echo "Hello World Website" >> index.html
git add index.html
git commit -m "Index HTML Commit"3
git status
Output: # On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
# (use "git push" to publish your local commits)
cd /root/sandbox/local_repo_original/ # Synchronization process
git pull /root/sandbox/local_repo_clone/
git status
cd /root/sandbox/local_repo_clone/
git config --global push.default matching # warning: push.default is unset;.. If encountered
git push
#[6] Exmaple: Remote Repository Clone and Sync
Git remote repo: server1.example.com
Local repo: station1.example.com
Remote repo: server1.example.com:/sandbox/gitrepo
Local repo: station1.example.com:/sandbox/localRepo
setup bi-directiobnal ssh password less authetication
#From station1.example.com,
git clone root@storage-gitlab-00-ah:/sandbox/gitrepo /sandbox/localRepo
cd /sandbox/localRepo
vim hello_world.sh # Simple bash script
vim hello_world.py # Simple python script
git add hello_world.py
git add hello_world.sh
git commit
git status # Your branch is ahead of 'origin/master' by 1 commit. .. Need to sync with the remote repo
#From server1.example.com,
cd /sandbox/gitrepo
git pull root@storage-gitlab-01-ah:/sandbox/localRepo
git status
#From station1.example.com,
git push
#[7] Example git log
git log -a # All logs
git log -p -2 # Latest two log
git log --stat
git log --pretty=oneline
git log --pretty=format:"%h: %an, %ae, %cn, %cd, - %s" --graph # an = author name; ae = author email; cn = commit name; cd = commit date;
#[8] Example git branching, merging and tag
mkdir -p /sandbox/ansible-development ; cd /sandbox/ansible-development/
git init # Copy some files to /sandbox/ansible-development
echo ".gitignore" >> .gitignore
echo "*.md" >> .gitignore
git add * # Follow example 5
git status # On branch master - nothing to commit, working directory clean
git checkout -b development # Create development branch
git checkout -b quality_testing # Create quality_testing brnach
git checkout -b sandbox # Create sandbox branch
git branch -a # List all branch
git checkout development # Switch to development branch
touch development_test.yaml # Create, add and commit in development branch, then switch to master branch, check whether master branch has the file created in development branch
git add development_test.yaml
git commit -m "Development Branch Commit"
git checkout master
ls -ltr # Check for file created in the development branch
git merge development --no-ff # Git merge, --no-ff = Retain all the commit messages prior to commmit
git tag -a Version-0.1 -m "Ansible Release -0.0.1" # Git tag - Similar like "zfs hold" - Annotatted tag
git tag Version1 # Git non-annotated tag
git tag # Git tag (immutable reference) - annotated & non-annotated
git show
git describe --tags
git branch -d <branch_name> # Delete a branch
#[8] Example pushing chages to remote repository
git push origin master
#[9] Example: diff between branches
git diff --name-status master..development # Diff between master and development branch
#[10] Example: Remote Repo Add
git remote add origin <remote repository>
git push origin master # Pushes the changes in local repository up to the remote repository
Important Files:
/etc/gitconfig # System config
/root/.gitconfig # Global config
# GET LOGS from POD
kubectl logs -n monitoring <pod>
# EXECUTE COMMANDS IN POD
# Get output from running 'date' command from pod mypod, using the first container by default
kubectl exec mypod date
# Get output from running 'date' command in ruby-container from pod mypod
kubectl exec mypod -c ruby-container date
# Switch to raw terminal mode, sends stdin to 'bash' in ruby-container from pod mypod
# and sends stdout/stderr from 'bash' back to the client
kubectl exec mypod -c ruby-container -i -t -- bash -il
# List contents of /usr from the first container of pod mypod and sort by modification time.
# If the command you want to execute in the pod has any flags in common (e.g. -i),
# you must use two dashes (--) to separate your command's flags/arguments.
# Also note, do not surround your command and its flags/arguments with quotes
# unless that is how you would execute it normally (i.e., do ls -t /usr, not "ls -t /usr").
kubectl exec mypod -i -t -- ls -t /usr
# Get output from running 'date' command from the first pod of the deployment mydeployment, using the first container by default
kubectl exec deploy/mydeployment date
# Get output from running 'date' command from the first pod of the service myservice, using the first container by default
kubectl exec svc/myservice date
# UPLOAD & DOWNLOAD CONTENT POD
kubectl cp ./uploads.tgz rumboaloeste/rumboaloeste-wordpress-7cf556f48d-4w697:/var/www/html/wp-content/uploads
# Requires that the 'tar' binary is present in your container
# image. If 'tar' is not present, 'kubectl cp' will fail.
# Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the default namespace
kubectl cp /tmp/foo_dir <some-pod>:/tmp/bar_dir
# Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container
kubectl cp /tmp/foo <some-pod>:/tmp/bar -c <specific-container>
# Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace <some-namespace>
kubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar
# Copy /tmp/foo from a remote pod to /tmp/bar locally
kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar
lxc sub-commands:
config Change container or server configuration options
console Interact with the container's console device and log
copy Copy containers within or in between LXD instances
delete Delete containers and snapshots
exec Execute commands in containers
file Manage files in containers
image Manipulate container images
info Show container or server information
launch Create and start containers from images
list List the existing containers
move Move containers within or in between LXD instances
network Manage and attach containers to networks
operation List, show and delete background operations
profile Manage container configuration profiles
publish Publish containers as images
remote Manage the list of remote LXD servers
rename Rename a container or snapshot
restart Restart containers
restore Restore containers from snapshots
snapshot Create container snapshots
start Start containers
stop Stop containers
storage Manage storage pools and volumes
#version lxc
lxc -v
#full info lxc
lxc info
#log info container
lxc info --show-log miguel-test
##### IMAGES LXC ######
#list images containers
lxc image list
#list image by column (size,description,fingerprint)
lxc image list -c sdf
lxc image copy ab48da5497de nova102
#alias of image
Lxc image alias [create/rename/delete]
#export images to tar
lxc image export ab48da5497de c7.tar
lxc image import <tarball>|<dir> [<rootfs tarball>|<URL>] [<remote>:] [--public] [--created-at=ISO-8601] [--expires-at=ISO-8601] [--fingerprint=FINGERPRINT] [--alias=ALIAS...] [prop=value]
Import an image tarball (or tarballs) or an image directory into the LXD image store.
Directory import is only available on Linux and must be performed as root.
lxc image copy [<remote>:]<image> <remote>: [--alias=ALIAS...] [--copy-aliases] [--public] [--auto-update]
Copy an image from one LXD daemon to another over the network.
The auto-update flag instructs the server to keep this image up to
date. It requires the source to be an alias and for it to be public.
lxc image delete [<remote>:]<image> [[<remote>:]<image>...]
Delete one or more images from the LXD image store.
lxc image refresh [<remote>:]<image> [[<remote>:]<image>...]
Refresh one or more images from its parent remote.
lxc image export [<remote>:]<image> [target]
Export an image from the LXD image store into a distributable tarball.
#### CONTAINERS LXC #######
# list containers
lxc list
#lxc info container
lxc info [container]
#create new container from other without snapshots
lxc copy mvtv-base miguel-test --container-only
#Move a container between two hosts, renaming it if destination name differs.
lxc move [<remote>:]<source container> [<remote>:][<destination container>] [--container-only]
#Rename a local container.
lxc move <old name> <new name> [--container-only]
#Rename a snapshot.
lxc move <container>/<old snapshot name> <container>/<new snapshot name>
#Manage container configuration profiles
lxc profile list [<remote>:]
List available profiles.
lxc profile show [<remote>:]<profile>
Show details of a profile.
lxc profile create [<remote>:]<profile>
Create a profile.
lxc profile copy [<remote>:]<profile> [<remote>:]<profile>
Copy the profile.
lxc profile get [<remote>:]<profile> <key>
Get profile configuration.
lxc profile set [<remote>:]<profile> <key> <value>
Set profile configuration.
lxc profile unset [<remote>:]<profile> <key>
Unset profile configuration.
lxc profile delete [<remote>:]<profile>
Delete a profile.
lxc profile edit [<remote>:]<profile>
Edit profile, either by launching external editor or reading STDIN.
lxc profile rename [<remote>:]<profile> <new-name>
Rename a profile.
#####Profile assignment#####
lxc profile assign [<remote>:]<container> <profiles>
Replace the current set of profiles for the container by the one provided.
lxc profile add [<remote>:]<container> <profile>
Add a profile to a container
lxc profile remove [<remote>:]<container> <profile>
Remove the profile from a container
#### Device management ####
lxc profile device list [<remote>:]<profile>
List devices in the given profile.
lxc profile device show [<remote>:]<profile>
Show full device details in the given profile.
lxc profile device remove [<remote>:]<profile> <name>
Remove a device from a profile.
lxc profile device get [<remote>:]<profile> <name> <key>
Get a device property.
lxc profile device set [<remote>:]<profile> <name> <key> <value>
Set a device property.
lxc profile device unset [<remote>:]<profile> <name> <key>
Unset a device property.
lxc profile device add [<remote>:]<profile> <device> <type> [key=value...]
Add a profile device, such as a disk or a nic, to the containers using the specified profile.
#Manage Config & files containers
# show config container
lxc config show miguel-test
#Edit config of container
lxc config edit miguel-test
#####Container configuration######
lxc config get [<remote>:][container] <key>
Get container or server configuration key.
lxc config set [<remote>:][container] <key> <value>
Set container or server configuration key.
#LIMITS :CPU - RAM ….
#https://github.com/lxc/lxd/blob/master/doc/containers.md
lab@nova101:~$ lxc config set miguel-test limits.cpu 1
lab@nova101:~$ lxc config set miguel-test limits.memory 512
#order boot on container list
lxc config set miguel-test boot.autostart.priority 1
#Seconds to wait for container to shutdown before it is force stopped
lxc config set miguel-test boot.host_shutdown_timeout 1
lxc config unset [<remote>:][container] <key>
Unset container or server configuration key.
lxc config show [<remote>:][container] [--expanded]
Show container or server configuration.
lxc config edit [<remote>:][container]
Edit configuration, either by launching external editor or reading STDIN.
*Container metadata*
lxc config metadata show [<remote>:][container]
Show the container metadata.yaml content.
lxc config metadata edit [<remote>:][container]
Edit the container metadata.yaml, either by launching external editor or reading STDIN.
*Container templates*
lxc config template list [<remote>:][container]
List the names of template files for a container.
lxc config template show [<remote>:][container] [template]
Show the content of a template file for a container.
lxc config template create [<remote>:][container] [template]
Add an empty template file for a container.
lxc config template edit [<remote>:][container] [template]
Edit the content of a template file for a container, either by launching external editor or reading STDIN.
lxc config template delete [<remote>:][container] [template]
Delete a template file for a container.
*Device management*
lxc config device add [<remote>:]<container> <device> <type> [key=value...]
Add a device to a container.
lxc config device get [<remote>:]<container> <device> <key>
Get a device property.
lxc config device set [<remote>:]<container> <device> <key> <value>
Set a device property.
lxc config device unset [<remote>:]<container> <device> <key>
Unset a device property.
lxc config device list [<remote>:]<container>
List devices for container.
lxc config device list miguel-test
lxc config device show [<remote>:]<container>
Show full device details for container.
lxc config device remove [<remote>:]<container> <name>...
Remove device from container.
*Client trust store management*
lxc config trust list [<remote>:]
List all trusted certs.
lxc config trust add [<remote>:] <certfile.crt>
Add certfile.crt to trusted hosts.
lxc config trust remove [<remote>:] [hostname|fingerprint]
Remove the cert from trusted hosts.
# LXC NETWORK
Manage and attach containers to networks.
lxc network list [<remote>:]
List available networks.
lxc network show [<remote>:]<network>
Show details of a network.
lxc network create [<remote>:]<network> [key=value...]
Create a network.
lxc network get [<remote>:]<network> <key>
Get network configuration.
lxc network set [<remote>:]<network> <key> <value>
Set network configuration.
lxc network unset [<remote>:]<network> <key>
Unset network configuration.
lxc network delete [<remote>:]<network>
Delete a network.
lxc network edit [<remote>:]<network>
Edit network, either by launching external editor or reading STDIN.
lxc network rename [<remote>:]<network> <new-name>
Rename a network.
lxc network attach [<remote>:]<network> <container> [device name] [interface name]
Attach a network interface connecting the network to a specified container.
lxc network attach-profile [<remote>:]<network> <profile> [device name] [interface name]
Attach a network interface connecting the network to a specified profile.
lxc network detach [<remote>:]<network> <container> [device name]
Remove a network interface connecting the network to a specified container.
lxc network detach-profile [<remote>:]<network> <container> [device name]
Remove a network interface connecting the network to a specified profile.
# MANAGE FILES
#Delete files in containers.
lxc file delete [<remote>:]<container>/<path> [[<remote>:]<container>/<path>...]
Manage files in containers.
lxc file pull [-r|--recursive] [<remote>:]<container>/<path> [[<remote>:]<container>/<path>...] <target path>
Pull files from containers.
lxc file push [-r|--recursive] [-p|--create-dirs] [--uid=UID] [--gid=GID] [--mode=MODE] <source path> [<source path>...] [<remote>:]<container>/<path>
Push files into containers.
lxc file delete [<remote>:]<container>/<path> [[<remote>:]<container>/<path>...]
Delete files in containers.
lxc file edit [<remote>:]<container>/<path>
Edit files in containers using the default text editor.
#attach network to containers
lxc network attach shitake-mgmt miguel-test eth0
lxc network attach shitake-be miguel-test eth1
Multiple hosts
The "lxc" command line tool can talk to multiple LXD servers and defaults to talking to the local one.
Remote operations require the following two commands having been run on the remote server:
lxc config set core.https_address "[::]"
lxc config set core.trust_password some-password
# lxc config set core.trust_password N0k1117.
The former tells LXD to bind all addresses on port 8443. The latter sets a trust password to be used by new clients.
Now to talk to that remote LXD, you can simply add it with:
lxc remote add host-a <ip address or DNS>
# lxc remote add nova102 10.95.67.73 --accept-certificate --password=N0k1117.
#montar algún directorio por NFS en un contenedor, tenéis que cargarle la siguiente configuración:
printf 'mount fstype=rpc_pipefs,\nmount fstype=nfs,' | lxc config set rebollon-asfoa-1b raw.apparmor –
lxc config set rebollon-asfoa-1b security.privileged true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment