Grep
ignore commented and empty lines
grep -v "^#\|^$" /path/to/dir
Home{blogsnippetsgalleryprojects} ;
ignore commented and empty lines
grep -v "^#\|^$" /path/to/dir
delete
:g/^#/d # delete all the lines starting with # g=>global d=>delete
:g/^\s*$/d # deleting all lines that are empty or that contain whitespace only
:g!/^\s*#/d # delete all the lines that are not comment
substitution
:%s/old/new/gc # substitute with prompt
& = repeat last substitution, in the current line
g& = repeat last substitution on all lines
repeat something
30i/I/a/A #horizontally
3o/O #vertically
extras
:set paste # allows pasting w/o indentation mess
C-x C-f # completing file names too, as well as
C-x C-l # completing entire lines.
Multi-line change
C-q # after rip-grep
:cdo %s/old/new/g # apply the regex accross all the quick fixlist
Context & Namespace
k config get-contexts # List all contexts
k config current-context # Show current context
Pods
k exec -it pod_name -c container_name -n namespace -- bash # Exec into a container shell
k logs pod_name -c container_name -n namespace # View logs for container
k logs --previous pod_name -c container_name -n namespace # View logs from previous crash
k logs pod_name --all-containers -n namespace # View logs from all containers
k top po pod_name --containers -n namespace # Show CPU & memory usage per container
k delete po pod_name -n namespace # Delete pod
Secrets
kubectl get secret datadog-agent -n namespace -o jsonpath='{.data.api-key}' | base64 -d
Deployments
k rollout restart deploy deploy_name -n namespace # Restart a deployment
HPA & Events
k describe hpa hpa_name -n namespace # Describe HPA details
k get ev --field-selector involvedObject.name=obj_name -n namespace # Get events for specific object
Stop typing long SSH commands! Use ~/.ssh/config
:
Host prod-server
HostName 192.168.1.100
User deploy
Port 2222
IdentityFile ~/.ssh/prod_key
ForwardAgent yes
Host dev-*
User developer
Port 22
IdentityFile ~/.ssh/dev_key
Now just type: ssh prod-server
or ssh dev-anything
Host frontend-github
HostName github.com
User git
IdentityFile ~/.ssh/ssh-frontend
IdentitiesOnly yes
git clone git@frontend-github:repo_link.git # replace github.com with frontend-github after key is added.
get in
docker exec -it container_name sh
clean up Docker system resources:
# Remove all stopped containers
docker container prune -f
# Remove unused images
docker image prune -a -f
# Remove unused volumes
docker volume prune -f
# Nuclear option - clean everything
docker system prune -a --volumes -f
Always be careful with the nuclear option in production!
Color Name | ANSI Code | Prompt Line |
---|---|---|
Red | 0;31 | export PS1='\[\e[0;31m\]\u@myhost:\w\$ \[\e[0m\]' |
Green | 0;32 | export PS1='\[\e[0;32m\]\u@myhost:\w\$ \[\e[0m\]' |
Yellow | 0;33 | export PS1='\[\e[0;33m\]\u@myhost:\w\$ \[\e[0m\]' |
Blue | 0;34 | export PS1='\[\e[0;34m\]\u@myhost:\w\$ \[\e[0m\]' |
Magenta | 0;35 | export PS1='\[\e[0;35m\]\u@myhost:\w\$ \[\e[0m\]' |
Cyan | 0;36 | export PS1='\[\e[0;36m\]\u@myhost:\w\$ \[\e[0m\]' |
White | 0;37 | export PS1='\[\e[0;37m\]\u@myhost:\w\$ \[\e[0m\]' |
Bright Red | 1;31 | export PS1='\[\e[1;31m\]\u@myhost:\w\$ \[\e[0m\]' |
Bright Green | 1;32 | export PS1='\[\e[1;32m\]\u@myhost:\w\$ \[\e[0m\]' |
Bright Blue | 1;34 | export PS1='\[\e[1;34m\]\u@myhost:\w\$ \[\e[0m\]' |
Python one-liners :
# Start a simple HTTP server
python -m http.server 8000
# Generate random password
python -c "import secrets, string; print(''.join(secrets.choice(string.ascii_letters + string.digits) for _ in range(12)))"