sh_config.sh 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. # ssh 配置
  2. alias ssh-tianyunperfect='ssh -i ~/.ssh/tianyun.pem root@www.tianyunperfect.cn'
  3. alias ssh-yizhi='ssh -i ~/.ssh/yizhi.pem root@www.yizhigj.com'
  4. # 快捷命令
  5. ## 未分类
  6. alias bing='open "https://www.bing.com/search?q=$1"'
  7. alias ll='ls -alh --time-style="+%Y-%m-%d %H:%I:%S"'
  8. #du -sh * 2>/dev/null | sort -hr
  9. alias du-sh='du -sh * 2>/dev/null | sort -hr'
  10. ## k8s
  11. function k8s-getnamespace() {
  12. kubectl config view | grep namespace
  13. }
  14. function k8s-setnamespace() {
  15. k8s-getnamespace
  16. kubectl config set-context --current --namespace="$1"
  17. }
  18. function k8s-getpod() {
  19. k8s-getnamespace
  20. # 如果有参数,则过滤
  21. if [ ! -z "$1" ]; then
  22. kubectl get pods -o wide | grep "$1"
  23. else
  24. kubectl get pods -o wide
  25. fi
  26. }
  27. alias k8s-descpods='kubectl describe pods'
  28. function k8s-getlog() {
  29. k8s-getnamespace
  30. podName=$(kubectl get pods -o wide | grep "${1}" | awk '{print $1}')
  31. kubectl logs --tail=300 -f "${podName}"
  32. }
  33. alias k8s-delpod='kubectl delete pod ${1} --force'
  34. function k8s-inpod() {
  35. k8s-getnamespace
  36. podName=$(kubectl get pods -o wide | grep "${1}" | awk '{print $1}')
  37. kubectl exec -it "${podName}" -- /bin/bash
  38. }
  39. alias k8s-getsvc='kubectl get svc'
  40. alias k8s-deldeployment='kubectl delete deployment'
  41. alias k8s-getdeployment='kubectl get deployment'
  42. alias k8s-descdeployment='kubectl describe deployment'
  43. alias k8s-getdeploymentgrep='kubectl get deployment | grep'
  44. alias k8s-getingress='kubectl get ingress'
  45. alias k8s-descingress='kubectl describe ingress'
  46. alias k8s-getingressgrep='kubectl get ingress | grep'
  47. ## docker
  48. alias docker-rm-all-image='docker rmi $(docker images -q)'
  49. alias docker-rm-all-docker='docker rm $(docker ps -a -q)'
  50. alias docker-show-image-prune='docker image ls -f dangling=true'
  51. alias docker-image-prune='docker image prune -a'
  52. alias dkstats='docker stats'
  53. alias dkps='docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"'
  54. alias dkpsa='docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"'
  55. alias dkrm='docker rm -f $1'
  56. alias dkrmi='docker rmi -f $1'
  57. alias dkimage='docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}\t{{.Size}}"'
  58. alias dkip='docker inspect --format="{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" $(docker ps -aq)'
  59. alias dkin='docker exec -it $1 /bin/bash'
  60. alias dklog='docker logs -n 300 -f $1'
  61. alias dkinspect='docker inspect $1'
  62. ## go
  63. alias gobuildwinexe='GOOS=windows GOARCH=amd64 go build -o $1.exe $1.go'
  64. alias gobuildlinuxexe='GOOS=linux GOARCH=amd64 go build -o $1 $1.go'
  65. alias gobuildmacexe='GOOS=darwin GOARCH=amd64 go build -o $1 $1.go'
  66. ## version
  67. alias python3version='python3 --version'
  68. alias javaversion='java -version'
  69. alias nodeversion='node -v'
  70. alias centosversion='cat /etc/os-release'
  71. alias ubuntuversion='cat /etc/lsb-release'
  72. alias goversion='go version'
  73. ## ip查看
  74. alias ipremote='curl cip.cc'
  75. function iplocal() {
  76. # 如果是mac 过滤 en0,如果是linux 过滤 eth0
  77. if [[ "$OSTYPE" == "darwin"* ]]; then
  78. ifconfig en0 | grep inet | grep -v inet6
  79. else
  80. ifconfig eth0 | grep inet | grep -v inet6
  81. fi
  82. }
  83. ## 进程相关
  84. alias psgrep='ps aux | grep -v grep | grep'
  85. alias killport='kill -9 $(lsof -t -i:$1)'
  86. alias ps-mem-top6='ps aux --sort=-%mem | awk '\''{print $2, $11, $4, $6/1024 "MB"}'\'' | head -n 6'
  87. # node
  88. alias npminstall='npm install -g --registry=https://registry.npmmirror.com '
  89. # python
  90. alias pipinstall='python3 -m pip install $1 -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com'
  91. # 文件查找相关
  92. alias findname='find . -name *$1*'
  93. alias grepR='grep -R -C 1 -n $1 .'
  94. # 备份
  95. function tar_back()
  96. {
  97. time=$(date "+%Y-%m-%d_%H_%M_%S")
  98. tar -zcvf "${1}".${time}.tgz "$1"
  99. ll -h ${1}.${time}.tgz
  100. }
  101. pid-cmd-centos(){
  102. sudo ls -l /proc/$1/cwd | awk '{print $11}'
  103. sudo cat /proc/$1/cmdline
  104. echo ''
  105. }
  106. pid-cmd-ubuntu() {
  107. ls -l /proc/"$1"/cwd | awk '{print $11}'
  108. tr '\0' ' ' </proc/"$1"/cmdline; echo ""
  109. }
  110. function echo-arthas-install() {
  111. echo '
  112. # 判断是否存在 ~/arthas-boot.jar,如果不存在则下载
  113. if [ ! -f ~/arthas-boot.jar ]; then
  114. ( cd ~ && curl -O https://arthas.gitee.io/arthas-boot.jar )
  115. fi
  116. # 判断是否在k8s里面
  117. if [[ ! -z "$KUBERNETES_SERVICE_HOST" && ! -z "$KUBERNETES_SERVICE_PORT" ]]; then
  118. echo "Running in Kubernetes environment"
  119. java -jar ~/arthas-boot.jar 1 --options json-format=true
  120. else
  121. echo "Not running in Kubernetes environment"
  122. java -jar ~/arthas-boot.jar --options json-format=true
  123. fi
  124. '
  125. }
  126. function curl-form() {
  127. curl -d "$2" "$1"
  128. }
  129. function watch-cpudiskmemory() {
  130. watch -n 1 '
  131. echo "===CPU占用摘要:"
  132. top -bn 1 -i -c | grep Cpu
  133. echo "
  134. ===内存占用摘要:"
  135. free -h
  136. echo "
  137. ===磁盘占用摘要:"
  138. df -h /'
  139. }
  140. #123
  141. function vimrc() {
  142. if [[ "$0" =~ "zsh" ]]
  143. then
  144. vim ~/.zshrc
  145. else
  146. vim ~/.bashrc
  147. fi
  148. }
  149. merge_video_audio() {
  150. if [ "$#" -ne 3 ]; then
  151. echo "错误:参数数量不正确!"
  152. echo "用法:merge_video_audio video.mp4 audio.mp3 output.mp4"
  153. return 1
  154. fi
  155. ffmpeg -i "$1" -i "$2" -c:v copy -c:a copy "$3"
  156. }
  157. rm-all() {
  158. find . -name $1 | xargs -I {} rm -rf {}
  159. }
  160. ### mysql
  161. function echo-mysql-tables() {
  162. echo 'SELECT table_name, table_comment FROM information_schema.tables WHERE table_schema = DATABASE();'
  163. }
  164. function echo-mysql-table-size() {
  165. echo 'select table_name,concat(round(sum(DATA_LENGTH/1024/1024),2),"MB") as data from information_schema.TABLES where table_schema =(SELECT DATABASE()) group by table_name;'
  166. }
  167. function echo-mysql-db-size() {
  168. echo 'select table_schema,concat(round(sum(DATA_LENGTH/1024/1024),2),"MB") as data from information_schema.TABLES where table_schema not in ("information_schema","mysql","performance_schema","sys") group by table_schema;'
  169. }
  170. function echo-npm() {
  171. echo '
  172. npm i webpack # 在module文件中安装
  173. npm i webpack -S # --save 常用,添加到package
  174. npm i webpack -D # --save-dev
  175. npm i webpack -g --registry=https://registry.npmmirror.com # 全局
  176. npm un webpack -g
  177. yarn add react
  178. yarn remove react
  179. yarn global add umi
  180. '
  181. }