alias pb='ping www.baidu.com' alias pg='ping www.google.com' alias cg='curl www.google.com' alias cgeo='curl cip.cc' alias v='nvim' alias ca='conda activate' alias cda='conda deactivate' alias renamehost="sudo hostnamectl set-hostname" # uv alias va='source .venv/bin/activate' alias vda='deactivate' alias sb='source ~/.bashrc' alias dirsize='du -h --max-depth=0' alias lh='ls -lh' # tmux aliases alias tn='tmux new -s' alias td='tmux detach -t' alias ta='tmux attach -t' alias ts='tmux switch -t' alias tk='tmux kill-session -t' alias tka='tmux kill-server' # other cli alias lf='llamafactory-cli' alias pipreqs='pipreqs . --force --encoding utf-8 --output-file requirements.txt' # 查看当前路径下的文件树 alias tr="tree -FLCN 2" # 查看当前路径下的文件夹 alias trd="tree -FLCNd 2" # 每 0.1 秒读取当前路径下的磁盘空间使用量,特别在下载模型的时候很好用 alias wdisk="watch -n 0.1 du -hs" # 查看所有 docker 容器的大小并且降序排列 alias dls="docker ps -a --format 'table {{.ID}}\t{{.Names}}\t{{.Size}}' | sort -k 3 -hr" # 查看指定 docker 容器的状态 function dgp() { if [ -z "$1" ]; then echo "请指定容器名称" return 1 fi docker ps -a --format "table {{.Names}}\t{{.Status}}\t{{.RunningFor}}" | grep "$1" | cat } function dsr() { if [ -z "$1" ]; then echo "请指定容器名称" return 1 fi docker stop "$1" && docker rm "$1" } ############################################################ # Cuda ############################################################ alias dw="WANDB_MODE='disabled'" alias nv='nvidia-smi' alias wnv='watch -n 0.5 nvidia-smi' alias c0='CUDA_VISIBLE_DEVICES=0' alias c1='CUDA_VISIBLE_DEVICES=1' alias c2='CUDA_VISIBLE_DEVICES=2' alias c3='CUDA_VISIBLE_DEVICES=3' alias c4='CUDA_VISIBLE_DEVICES=4' alias c5='CUDA_VISIBLE_DEVICES=5' alias c6='CUDA_VISIBLE_DEVICES=6' alias c7='CUDA_VISIBLE_DEVICES=7' alias cnan='CUDA_VISIBLE_DEVICES=""' alias unset_cuda='unset CUDA_VISIBLE_DEVICES' # cuda 1,2,3,4,5,6,7 python xxx.py function cuda () { local devs=$1 shift CUDA_VISIBLE_DEVICES="$devs" "$@" } function gpu_num () { python -c "import torch; print('Num gpus:',torch.cuda.device_count());" } ############################################################ # Python ############################################################ # generate minimal requirements alias gen_reqs='pipreqs . --force --encoding utf-8 --output-file requirements.txt' alias tspip="pip install -i https://pypi.tuna.tsinghua.edu.cn/simple" alias pypi='pip install -i https://pypi.python.org/simple' alias mrpip="pip install -i https://mirrors.cernet.edu.cn/pypi/web/simple" function runpy () { python -c "$1" # python -c "$1" | tee /dev/tty } ############################################################ # Proxy ############################################################ alias px='proxychains' alias px4='proxychains4' export PHOST=127.0.0.1 # 应当在 .zshrc 最后覆盖 export PPORT=7890 function tproxy(){ # 检查是否提供了参数。如果没有,使用默认值。 # 语法:${1:-defaultValue} 表示如果第一个参数为空或未设置,则使用defaultValue。 local PHOST=${1:-127.0.0.1} local PPORT=${2:-7890} # 导出环境变量 export https_proxy="http://$PHOST:$PPORT" export http_proxy="http://$PHOST:$PPORT" export all_proxy="socks5://$PHOST:$PPORT" echo "代理已设置: $PHOST:$PPORT" } function utproxy(){ unset https_proxy unset http_proxy unset all_proxy echo "代理已关闭" } # proxy from personal computer # zsh 需要 function 关键字 bash 不需要 function proxy_pc(){ pc_ip=$(env | grep SSH_CONNECTION | awk -F '=' '{print $2}' | awk -F ' ' '{print $1}') export https_proxy=http://${pc_ip}:$PPORT http_proxy=http://${pc_ip}:$PPORT all_proxy=socks5://${pc_ip}:$PPORT echo "代理已设置为 ${pc_ip}:$PPORT" } function proxy_off(){ unset https_proxy http_proxy all_proxy } # 更优雅的方式 alias ssht='ssh -R 7890:localhost:7890' ############################################################ # Sync ############################################################ upload_file() { local local_file=$1 local remote_user="qing" local remote_host=$2 local remote_path=$3 echo "Syncing $local_file to $remote_user@$remote_host:$remote_path..." scp "$local_file" "$remote_user@$remote_host:$remote_path" echo "Done syncing $local_file to $remote_user@$remote_host:$remote_path" echo "" } sync_aliases() { local aliases_file="/Users/qing/.bash_aliases" local remote_user="qing" local remote_hosts=("map" "hitk" "bleu" "auc" "f1" "recall" "precision" "aliqserver" "qserver" "ukqserver") for host in "${remote_hosts[@]}"; do upload_file "$aliases_file" "$host" "~/.bash_aliases" done } ############################################################ # services ############################################################ alias vnckill='vncserver -kill :1' alias vncstart='vncserver :1 -geometry 1920x1080 -depth 24 -localhost=no' # -localhost=no 使得可以远程连接, netstat -tuln | grep 5901 查看端口是否开启, tcp 0 0 0.0.0.0:5901 才对 function dockge() { cd /opt/dockge # 检查 dockge 容器是否已经在运行 if sudo docker compose ps --services --filter "status=running" | grep -q .; then echo "Dockge is already running" echo "open in the browser to manage services" else echo "Starting Dockge..." sudo docker compose up -d if [ $? -eq 0 ]; then echo "Dockge started successfully" echo "open in the browser to start services" else echo "Failed to start Dockge" fi fi }