sh_config.sh 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 ll='ls -alh --time-style="+%Y-%m-%d %H:%I:%S"'
  7. #du -sh * 2>/dev/null | sort -hr
  8. alias du-sh='du -sh * 2>/dev/null | sort -hr'
  9. alias sourcevenv='source venv/bin/activate'
  10. alias notify='function _notify() { osascript -e "display notification \"$1\""; }; _notify'
  11. alias weather='curl wttr.in/beijing'
  12. alias dust1='dust -d 1'
  13. function git_tag_push() {
  14. if [ $# -ne 2 ]; then
  15. echo "需要两个参数: <变量1> <变量2>"
  16. return 1
  17. fi
  18. git tag -a $1 -m "$2"
  19. git push origin $1
  20. }
  21. alias git_tags='git --no-pager tag -l -n'
  22. ## k8s
  23. function k8s-getnamespace() {
  24. kubectl config view | grep namespace
  25. }
  26. function k8s-setnamespace() {
  27. k8s-getnamespace
  28. kubectl config set-context --current --namespace="$1"
  29. }
  30. function k8s-getpod() {
  31. k8s-getnamespace
  32. # 如果有参数,则过滤
  33. if [ ! -z "$1" ]; then
  34. kubectl get pods -o wide | grep "$1"
  35. else
  36. kubectl get pods -o wide
  37. fi
  38. }
  39. alias k8s-descpods='kubectl describe pods'
  40. function k8s-getlog() {
  41. k8s-getnamespace
  42. podName=$(kubectl get pods -o wide | grep "${1}" | awk '{print $1}')
  43. kubectl logs --tail=300 -f "${podName}"
  44. }
  45. alias k8s-delpod='kubectl delete pod ${1} --force'
  46. function k8s-inpod() {
  47. k8s-getnamespace
  48. podName=$(kubectl get pods -o wide | grep "${1}" | awk '{print $1}')
  49. kubectl exec -it "${podName}" -- /bin/bash
  50. }
  51. alias k8s-getsvc='kubectl get svc'
  52. alias k8s-deldeployment='kubectl delete deployment'
  53. alias k8s-getdeployment='kubectl get deployment'
  54. alias k8s-descdeployment='kubectl describe deployment'
  55. alias k8s-getdeploymentgrep='kubectl get deployment | grep'
  56. alias k8s-getingress='kubectl get ingress'
  57. alias k8s-descingress='kubectl describe ingress'
  58. alias k8s-getingressgrep='kubectl get ingress | grep'
  59. ## docker
  60. alias docker-rm-all-image='docker rmi $(docker images -q)'
  61. alias docker-rm-all-docker='docker rm $(docker ps -a -q)'
  62. alias docker-show-image-prune='docker image ls -f dangling=true'
  63. alias docker-image-prune='docker image prune -a'
  64. alias dkstats='docker stats'
  65. alias dkps='docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"'
  66. alias dkpsa='docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"'
  67. alias dkrm='docker rm -f $1'
  68. alias dkrmi='docker rmi -f $1'
  69. alias dkimage='docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}\t{{.Size}}"'
  70. alias dkip='docker inspect --format="{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" $(docker ps -aq)'
  71. alias dkin='docker exec -it $1 /bin/bash'
  72. alias dklog='docker logs -n 300 -f $1'
  73. alias dkinspect='docker inspect $1'
  74. ## go
  75. alias gobuildwinexe='GOOS=windows GOARCH=amd64 go build -o $1.exe $1.go'
  76. alias gobuildlinuxexe='GOOS=linux GOARCH=amd64 go build -o $1 $1.go'
  77. alias gobuildmacexe='GOOS=darwin GOARCH=amd64 go build -o $1 $1.go'
  78. ## version
  79. alias pythonversion='python --version'
  80. alias javaversion='java -version'
  81. alias nodeversion='node -v'
  82. alias centosversion='cat /etc/os-release'
  83. alias ubuntuversion='cat /etc/lsb-release'
  84. alias goversion='go version'
  85. ## ip查看
  86. alias ipremote='curl cip.cc'
  87. function iplocal() {
  88. # 如果是mac 过滤 en0,如果是linux 过滤 eth0
  89. if [[ "$OSTYPE" == "darwin"* ]]; then
  90. ifconfig en0 | grep inet | grep -v inet6
  91. else
  92. ifconfig eth0 | grep inet | grep -v inet6
  93. fi
  94. }
  95. ## 进程相关
  96. alias psgrep='ps aux | grep -v grep | grep'
  97. alias killport='kill -9 $(lsof -t -i:$1)'
  98. alias ps-mem-top6='ps aux --sort=-%mem | awk '\''{print $2, $11, $4, $6/1024 "MB"}'\'' | head -n 6'
  99. # node
  100. alias npminstall='npm install -g --registry=https://registry.npmmirror.com '
  101. # python
  102. alias pipinstall='pip install $1 -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com'
  103. # 文件查找相关
  104. alias findname='find . -name *$1*'
  105. alias grepR='grep -R -C 1 -n $1 .'
  106. # 备份
  107. function tar_back()
  108. {
  109. time=$(date "+%Y-%m-%d_%H_%M_%S")
  110. tar -zcvf "${1}".${time}.tgz "$1"
  111. ll -h ${1}.${time}.tgz
  112. }
  113. pid-cmd-centos(){
  114. sudo ls -l /proc/$1/cwd | awk '{print $11}'
  115. sudo cat /proc/$1/cmdline
  116. echo ''
  117. }
  118. pid-cmd-ubuntu() {
  119. ls -l /proc/"$1"/cwd | awk '{print $11}'
  120. tr '\0' ' ' </proc/"$1"/cmdline; echo ""
  121. }
  122. function echo-arthas-install() {
  123. echo '
  124. # 判断是否存在 ~/arthas-boot.jar,如果不存在则下载
  125. if [ ! -f ~/arthas-boot.jar ]; then
  126. ( cd ~ && curl -O https://arthas.gitee.io/arthas-boot.jar )
  127. fi
  128. # 判断是否在k8s里面
  129. if [[ ! -z "$KUBERNETES_SERVICE_HOST" && ! -z "$KUBERNETES_SERVICE_PORT" ]]; then
  130. echo "Running in Kubernetes environment"
  131. java -jar ~/arthas-boot.jar 1 --options json-format=true
  132. else
  133. echo "Not running in Kubernetes environment"
  134. java -jar ~/arthas-boot.jar --options json-format=true
  135. fi
  136. '
  137. }
  138. alias cparthas='echo-arthas-install | pbcopy'
  139. function curl-form() {
  140. curl -d "$2" "$1"
  141. }
  142. function watch-cpudiskmemory() {
  143. watch -n 1 '
  144. echo "===CPU占用摘要:"
  145. top -bn 1 -i -c | grep Cpu
  146. echo "
  147. ===内存占用摘要:"
  148. free -h
  149. echo "
  150. ===磁盘占用摘要:"
  151. df -h /'
  152. }
  153. #123
  154. function vimrc() {
  155. if [[ "$0" =~ "zsh" ]]
  156. then
  157. vim ~/.zshrc
  158. else
  159. vim ~/.bashrc
  160. fi
  161. }
  162. merge_video_audio() {
  163. if [ "$#" -ne 3 ]; then
  164. echo "错误:参数数量不正确!"
  165. echo "用法:merge_video_audio video.mp4 audio.mp3 output.mp4"
  166. return 1
  167. fi
  168. ffmpeg -i "$1" -i "$2" -c:v copy -c:a copy "$3"
  169. }
  170. rm-all() {
  171. find . -name $1 | xargs -I {} rm -rf {}
  172. }
  173. ### mysql
  174. function echo-mysql-tables() {
  175. echo 'SELECT table_name, table_comment FROM information_schema.tables WHERE table_schema = DATABASE();'
  176. }
  177. function echo-mysql-table-size() {
  178. 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;'
  179. }
  180. function echo-mysql-db-size() {
  181. 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;'
  182. }
  183. function echo-npm() {
  184. echo '
  185. npm i webpack # 在module文件中安装
  186. npm i webpack -S # --save 常用,添加到package
  187. npm i webpack -D # --save-dev
  188. npm i webpack -g --registry=https://registry.npmmirror.com # 全局
  189. npm un webpack -g
  190. yarn add react
  191. yarn remove react
  192. yarn global add umi
  193. '
  194. }
  195. concat_params() {
  196. # 获取传入的参数个数
  197. num_params=$#
  198. # 判断参数个数是否大于等于1
  199. if [ $num_params -ge 1 ]; then
  200. # 使用循环遍历参数,并拼接在一起
  201. concat_str="$1"
  202. for ((i=2; i<=$num_params; i++)); do
  203. concat_str+="%20${!i}"
  204. done
  205. # 打印拼接后的字符串
  206. echo "$concat_str"
  207. else
  208. echo "没有传入参数"
  209. fi
  210. }
  211. function url_encode() {
  212. echo "$1" | sed 's/ /%20/g'
  213. }
  214. function bing() {
  215. ## 如果是windows系统,则使用start,否则使用open,后面的参数可以有多个空格
  216. if [[ "$OSTYPE" == "msys"* ]]; then
  217. search_query=$(concat_params "$@")
  218. start "https://www.bing.com/search?q=$search_query"
  219. else
  220. search_query=""
  221. for query in "$@"; do
  222. search_query+=" $query"
  223. done
  224. search_query=$(url_encode "$search_query")
  225. open "https://www.bing.com/search?q=${search_query}"
  226. fi
  227. }