123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- # ssh 配置
- alias ssh-tianyunperfect='ssh -i ~/.ssh/tianyun.pem root@www.tianyunperfect.cn'
- alias ssh-yizhi='ssh -i ~/.ssh/yizhi.pem root@www.yizhigj.com'
- # 快捷命令
- ## 未分类
- alias ll='ls -alh --time-style="+%Y-%m-%d %H:%I:%S"'
- #du -sh * 2>/dev/null | sort -hr
- alias du-sh='du -sh * 2>/dev/null | sort -hr'
- ## k8s
- function k8s-getnamespace() {
- kubectl config view | grep namespace
- }
- function k8s-setnamespace() {
- k8s-getnamespace
- kubectl config set-context --current --namespace="$1"
- }
- function k8s-getpod() {
- k8s-getnamespace
- # 如果有参数,则过滤
- if [ ! -z "$1" ]; then
- kubectl get pods -o wide | grep "$1"
- else
- kubectl get pods -o wide
- fi
- }
- alias k8s-descpods='kubectl describe pods'
- function k8s-getlog() {
- k8s-getnamespace
- podName=$(kubectl get pods -o wide | grep "${1}" | awk '{print $1}')
- kubectl logs --tail=300 -f "${podName}"
- }
- alias k8s-delpod='kubectl delete pod ${1} --force'
- function k8s-inpod() {
- k8s-getnamespace
- podName=$(kubectl get pods -o wide | grep "${1}" | awk '{print $1}')
- kubectl exec -it "${podName}" -- /bin/bash
- }
- alias k8s-getsvc='kubectl get svc'
- alias k8s-deldeployment='kubectl delete deployment'
- alias k8s-getdeployment='kubectl get deployment'
- alias k8s-descdeployment='kubectl describe deployment'
- alias k8s-getdeploymentgrep='kubectl get deployment | grep'
- alias k8s-getingress='kubectl get ingress'
- alias k8s-descingress='kubectl describe ingress'
- alias k8s-getingressgrep='kubectl get ingress | grep'
- ## docker
- alias docker-rm-all-image='docker rmi $(docker images -q)'
- alias docker-rm-all-docker='docker rm $(docker ps -a -q)'
- alias docker-show-image-prune='docker image ls -f dangling=true'
- alias docker-image-prune='docker image prune -a'
- alias dkstats='docker stats'
- alias dkps='docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"'
- alias dkpsa='docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"'
- alias dkrm='docker rm -f $1'
- alias dkrmi='docker rmi -f $1'
- alias dkimage='docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}\t{{.Size}}"'
- alias dkip='docker inspect --format="{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" $(docker ps -aq)'
- alias dkin='docker exec -it $1 /bin/bash'
- alias dklog='docker logs -n 300 -f $1'
- alias dkinspect='docker inspect $1'
- ## go
- alias gobuildwinexe='GOOS=windows GOARCH=amd64 go build -o $1.exe $1.go'
- alias gobuildlinuxexe='GOOS=linux GOARCH=amd64 go build -o $1 $1.go'
- alias gobuildmacexe='GOOS=darwin GOARCH=amd64 go build -o $1 $1.go'
- ## version
- alias python3version='python3 --version'
- alias javaversion='java -version'
- alias nodeversion='node -v'
- alias centosversion='cat /etc/os-release'
- alias ubuntuversion='cat /etc/lsb-release'
- alias goversion='go version'
- ## ip查看
- alias ipremote='curl cip.cc'
- function iplocal() {
- # 如果是mac 过滤 en0,如果是linux 过滤 eth0
- if [[ "$OSTYPE" == "darwin"* ]]; then
- ifconfig en0 | grep inet | grep -v inet6
- else
- ifconfig eth0 | grep inet | grep -v inet6
- fi
- }
- ## 进程相关
- alias psgrep='ps aux | grep -v grep | grep'
- alias killport='kill -9 $(lsof -t -i:$1)'
- alias ps-mem-top6='ps aux --sort=-%mem | awk '\''{print $2, $11, $4, $6/1024 "MB"}'\'' | head -n 6'
- # node
- alias npminstall='npm install -g --registry=https://registry.npmmirror.com '
- # python
- alias pipinstall='python3 -m pip install $1 -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com'
- # 文件查找相关
- alias findname='find . -name *$1*'
- alias grepR='grep -R -C 1 -n $1 .'
- # 备份
- function tar_back()
- {
- time=$(date "+%Y-%m-%d_%H_%M_%S")
- tar -zcvf "${1}".${time}.tgz "$1"
- ll -h ${1}.${time}.tgz
- }
- pid-cmd-centos(){
- sudo ls -l /proc/$1/cwd | awk '{print $11}'
- sudo cat /proc/$1/cmdline
- echo ''
- }
- pid-cmd-ubuntu() {
- ls -l /proc/"$1"/cwd | awk '{print $11}'
- tr '\0' ' ' </proc/"$1"/cmdline; echo ""
- }
- function echo-arthas-install() {
- echo '
- # 判断是否存在 ~/arthas-boot.jar,如果不存在则下载
- if [ ! -f ~/arthas-boot.jar ]; then
- ( cd ~ && curl -O https://arthas.gitee.io/arthas-boot.jar )
- fi
- # 判断是否在k8s里面
- if [[ ! -z "$KUBERNETES_SERVICE_HOST" && ! -z "$KUBERNETES_SERVICE_PORT" ]]; then
- echo "Running in Kubernetes environment"
- java -jar ~/arthas-boot.jar 1 --options json-format=true
- else
- echo "Not running in Kubernetes environment"
- java -jar ~/arthas-boot.jar --options json-format=true
- fi
- '
- }
- function curl-form() {
- curl -d "$2" "$1"
- }
- function watch-cpudiskmemory() {
- watch -n 1 '
- echo "===CPU占用摘要:"
- top -bn 1 -i -c | grep Cpu
- echo "
- ===内存占用摘要:"
- free -h
- echo "
- ===磁盘占用摘要:"
- df -h /'
- }
- #123
- function vimrc() {
- if [[ "$0" =~ "zsh" ]]
- then
- vim ~/.zshrc
- else
- vim ~/.bashrc
- fi
- }
- merge_video_audio() {
- if [ "$#" -ne 3 ]; then
- echo "错误:参数数量不正确!"
- echo "用法:merge_video_audio video.mp4 audio.mp3 output.mp4"
- return 1
- fi
- ffmpeg -i "$1" -i "$2" -c:v copy -c:a copy "$3"
- }
- rm-all() {
- find . -name $1 | xargs -I {} rm -rf {}
- }
- ### mysql
- function echo-mysql-tables() {
- echo 'SELECT table_name, table_comment FROM information_schema.tables WHERE table_schema = DATABASE();'
- }
- function echo-mysql-table-size() {
- 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;'
- }
- function echo-mysql-db-size() {
- 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;'
- }
- function echo-npm() {
- echo '
- npm i webpack # 在module文件中安装
- npm i webpack -S # --save 常用,添加到package
- npm i webpack -D # --save-dev
- npm i webpack -g --registry=https://registry.npmmirror.com # 全局
- npm un webpack -g
- yarn add react
- yarn remove react
- yarn global add umi
- '
- }
- concat_params() {
- # 获取传入的参数个数
- num_params=$#
- # 判断参数个数是否大于等于1
- if [ $num_params -ge 1 ]; then
- # 使用循环遍历参数,并拼接在一起
- concat_str="$1"
- for ((i=2; i<=$num_params; i++)); do
- concat_str+="%20${!i}"
- done
- # 打印拼接后的字符串
- echo "$concat_str"
- else
- echo "没有传入参数"
- fi
- }
- function bing() {
- # 获取拼接后的搜索参数
- search_query=$(concat_params "$@")
- ## 如果是windows系统,则使用start,否则使用open,后面的参数可以有多个空格
- if [[ "$OSTYPE" == "msys"* ]]; then
- start "https://www.bing.com/search?q=$search_query"
- else
- open "https://www.bing.com/search?q=$search_query"
- fi
- }
|