Handy Command

just copy and use it

word counts

script
1
grep  filename | wc -l

shell if

script
1
2
3
4
5
6
7
aflag=$(grep filename | wc -l)
if[[$aflag -eq 1]]
then
sed xxxx
else
echo "done"
fi

bash Grep & find & env & str

script
1
2
3
4
5
for pat in `find . -name "log4j*"` ; do unzip -p $package META-INF/MANIFEST.MF | grep Implementation-Version; done; // dump and grep key value
${str::-n} // delete last n byte
kubectl get pvc -n pt | grep zookeeper | head -n 100 | awk '{print $1}' | xargs kubectl delte pvc -n pt
bash JAVA_HOME=xxx scripts // activate env for certain command
aws --profile=saml cloudtrail lookup-events --lookup-aatributes xxx | grep -o -P '.{1,3}xxx.{0,200}' // grep and print certain length of content

run docker as a root user

script
1
docker container exec -u 0 -it mycontainer bash

pip install with Cert

script
1
pip install requests --cert *.pem --trusted-host *.xxx.com --index-url https://username:password@repolink

CPU usage

script
1
2
println "uptime".execute().text
println "mpstat -P ALL".execute

Get current available physical on windows

systeminfo | find “Available Physical Memory”

k8s command

script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
export http_proxy=
unset http_proxy

helm list -n namespace
helm install --dry-run --debug ./foldername --generate-name
helm install ./foldername --create-namespace -n present-test --generate-name
helm delete xxx -n namespace

kubectl get pods -n namespace
kubectl describe pod pod_name -n namespace
kubectl exec -it xxx -n namespace -- sh
kubectl get pvc
kubectl delete pvc xxx
kubectl create secret generic xxx_secret --from-literal=DB_USER=*** --from-literal=DB_PASSWORD='***' -n namespace
kubectl get sa(service Account)
kubectl describe sa

special char

u”\u00b0” = °

C Pointer

script
1
2
3
4
5
6
7
8
9
10
11
int a[10];
int *pa;
pa = &a[0];
pa == a;
a[i] == *(a+i)
pa[i] == *(pa+i)
pa++ legal
a++ illegal
The
meaning of ``adding 1 to a pointer,'' and by extension, all pointer arithmetic, is that pa+1 points
to the next object