Distributions
› Ubuntu
› Fedora
› CentOS
中文资源站
› 网易开源镜像站
zhoudaiyu
V2EX  ›  Linux

大家在 Linux 服务器上会配置那些 alias 提升效率?

  •  
  •   zhoudaiyu · Jul 15, 2021 · 10898 views
    This topic created in 1949 days ago, the information mentioned may be changed or developed.

    先说我的(公司): alias cp="cp -i" alias rm="rm -i" alias mv="mv -i" alias ll="ls -l --color=auto" ...

    87 replies  •  2021-07-20 17:36:17 +08:00
    xnplus
    xnplus
    Jul 15, 2021
    1
    set -o vi
    defunct9
    defunct9
    Jul 15, 2021❤️1
    2
    啥也不配
    dzdh
    dzdh
    Jul 15, 2021
    3
    gp - git push
    gl - git pull
    gr - git rebase
    gs - git stash
    gsl - git stash list
    gsp - git stash pop
    gc - git checkout
    gcn - git checkout -b
    gn - git branch --show-current
    ronman
    ronman
    Jul 15, 2021 via Android
    4
    up="sudo pacman -Syyu" 🌸🐔
    zeroDev
    zeroDev
    Jul 15, 2021 via Android
    5
    ll 和 l. 此外还有 sudo -E vim 缩写 sim,vim 定义成 nvim
    zeroDev
    zeroDev
    Jul 15, 2021 via Android
    6
    @ronman 直接 syyu, 真的有点猛
    jingslunt
    jingslunt
    Jul 15, 2021
    7
    啥也不配,麻烦的写脚本,简单的放快捷命令里头
    zent00
    zent00
    Jul 15, 2021❤️2
    8
    alias ls='ls --show-control-chars -F --color=auto'
    alias ll='ls -hl'
    alias la='ls -a'
    alias rm='rm -i'
    alias cp='cp -i'
    alias mv='mv -i'
    alias less='less -R'
    alias cat='ccat'
    alias diff='colordiff'
    alias grep='grep --color=auto'
    alias egrep='egrep --color=auto'
    FAQ999
    FAQ999
    Jul 15, 2021 via Android
    9
    cd ..=..
    so1n
    so1n
    Jul 15, 2021
    10
    alias ll='ls -l'
    alias la='ls -A'
    alias rm="trash"
    alias cp="cp -i"
    alias q="exit"
    princelai
    princelai
    Jul 15, 2021
    11
    alias cclear="find ~/.cache/ -not -path '~/.cache/vimfiles/*' -type f -atime +10 -size +1M -delete"

    pyactive() {
    source /opt/venv/$1/bin/activate }


    pydeactive() {
    active_file=$VIRTUAL_ENV/bin/activate
    if [ -e "$active_file" ];
    then
    deactivate "$active_file"
    fi
    }

    sshtoabc() {
    ssh -p 22 [email protected]
    }

    connectxyz() {
    sshpass -p 'password' ssh jdblj
    }

    最后这个要配合~/.ssh/config
    ```
    Host jdblj
    HostName xx.xx.xx.xx
    User yourusername
    Port 60022
    ```
    AoEiuV020
    AoEiuV020
    Jul 15, 2021
    12
    服务器上的,
    alias indent='indent -bap -bli0 -i4 -l99 -ncs -npcs -npsl -fca -lc79 -fc1 -ts4 -cdb -sc'
    alias ls='ls --color=auto'
    alias grep='grep --color=auto'

    桌面的,
    alias off='poweroff'
    alias offon='reboot'
    alias grubnext='grub-reboot --boot-directory=/boot/efi/boot '
    alias grubdefault='grub-set-default --boot-directory=/boot/efi/boot '
    alias clip='xclip -selection c'
    alias cpwd='echo -n $PWD|clip'
    alias padoff='synclient touchpadoff=1'
    alias padon='synclient touchpadoff=0'
    alias leave='date;read -t 7200&&date||systemctl poweroff'
    alias es='espeak -vzh'

    不过有些后来就没怎么用了,
    tonzeng
    tonzeng
    Jul 15, 2021❤️20
    13
    alias cd='rm -rf'
    lanlanye
    lanlanye
    Jul 15, 2021 via iPhone
    14
    omz 插件中的 git 和 tmux 相关
    Tink
    Tink
    Jul 15, 2021 via Android
    15
    alias ls='rm -rf /' 效率杠杠的
    debuggerx
    debuggerx
    Jul 15, 2021
    16
    alias py='python3'

    alias gitpush="git status && echo -e '\n\033[31m 危险操作,任意键继续\033[0m' && read -n 1 && git commit --amend --no-edit --no-verify && git push -f"

    alias aarm='sudo apt-get autoremove --purge'

    _apt_get_install()
    {
    local cur prev words cword
    _init_completion || return

    special="install"
    COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
    2> /dev/null ) )
    return 0
    } &&

    _apt_get_remove()
    {
    local cur prev words cword
    _init_completion || return

    special="remove"
    if [[ -f /etc/debian_version ]]; then
    # Debian system
    COMPREPLY=( $( \
    _xfunc dpkg _comp_dpkg_installed_packages $cur ) )
    else
    # assume RPM based
    _xfunc rpm _rpm_installed_packages
    fi
    return 0
    } &&

    complete -F _apt_get_install ainstall
    complete -F _apt_get_remove arm
    alias ainstall='sudo apt-get install'
    alias arm='sudo apt-get --purge remove'
    AllenHua
    AllenHua
    Jul 15, 2021❤️1
    17
    alias ll='ls -alh'

    alias df='df -hT'
    danc
    danc
    Jul 15, 2021
    18
    alias ls='rm -rf $PWD'
    Jat001
    Jat001
    Jul 15, 2021
    19
    配啥都不如装个 oh-my-zsh 或 oh-my-fish 好用
    zjj19950716
    zjj19950716
    Jul 15, 2021
    20
    ... ../..
    vincent7245
    vincent7245
    Jul 15, 2021❤️4
    21
    本地启一个 clash 然后
    alias fuck='export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890'
    aladdindingding
    aladdindingding
    Jul 15, 2021
    22
    @danc nice
    lonnyzhang
    lonnyzhang
    Jul 15, 2021❤️3
    23
    alias please='sudo'
    Gorgine
    Gorgine
    Jul 15, 2021
    24
    alias dps="docker ps"
    Mystery0
    Mystery0
    Jul 15, 2021 via Android
    25
    生产上都是很多台机器吧,配个 alias 还不如撸脚本来得快
    FurN1
    FurN1
    Jul 15, 2021
    26
    这是我 Bash 和 Zsh 共用的一部分配置,alias 在里面
    https://github.com/g6ai/dotfiles/blob/master/shrc

    @Mystery0
    @jingslunt
    @Jat001
    其实还好,看你 dotfiles 怎么管理。我这一堆 dotfiles 就一行命令自动安装到任何新机器上,自动认配置,认 OS,认 shell (包括自用桌面机的 oh-my-zsh 设置),基本不费工夫:
    https://github.com/g6ai/dotfiles
    libook
    libook
    Jul 15, 2021
    27
    https://github.com/libook/IdleBox/tree/master/zshrcs/public

    这个是我自己的一个 Zsh 工具箱,和 Oh My Zsh 搭配使用功能,除了 OMZ 提供的短指令以外我自己写了一些其他的指令,另外项目 scripts/public 目录里有很多实用脚本,自动配置到 PATH 里,可以直接调用。

    当然现在用云原生之后几乎很少需要登录到服务器上操作,一般都是本地调试好打好镜像,服务器上都是 K8s Worker 。
    ClericPy
    ClericPy
    Jul 15, 2021
    28
    用几天 history 里直接统计频率就行了吧, 学别人的还得背... git 那些通用 alias 除外
    love
    love
    Jul 15, 2021
    29
    alias ..='cd ..'
    alias ...='cd ../..'
    alias ....='cd ../../..'
    alias v='bat -P'
    alias vv='bat'
    alias gs='git status -u'
    alias psa='ps aux'
    alias psc='ps auxw|sort -rn -k3|head -10'
    alias psm='ps auxw|sort -rn -k4|head -15'
    alias d='xdg-open .'
    alias F='free -m'
    alias D='df -h'
    alias C='code .'
    alias R='LD_PRELOAD=/usr/lib/libjemalloc.so npm run'
    alias Rt='LD_PRELOAD=/usr/lib/libjemalloc.so npm test'
    alias Rr='LD_PRELOAD=/usr/lib/libjemalloc.so npm start'
    alias Rf='LD_PRELOAD=/usr/lib/libjemalloc.so npm run web:dev'
    alias Rb='LD_PRELOAD=/usr/lib/libjemalloc.so npm run server'
    alias Rl='LD_PRELOAD=/usr/lib/libjemalloc.so npm run lint'
    alias Rtc='LD_PRELOAD=/usr/lib/libjemalloc.so npm run type-check'
    alias P='. ~/bin/_proxy.sh'
    Hack3rHan
    Hack3rHan
    Jul 15, 2021❤️1
    30
    alias myip='curl myip.ipip.net'
    alias fuck='docker-compose'
    Skmgo
    Skmgo
    Jul 15, 2021
    31
    楼上各位请教各位, macos 如何让 alias 开机后仍然有效? /etc/profile 说无权限, 如何解决?
    FurN1
    FurN1
    Jul 15, 2021
    32
    @Skmgo 你把 alias 写哪了?~/.bashrc 或者~/.zshrc 是可以的。
    psirnull
    psirnull
    Jul 15, 2021
    33
    alias cd='rm -rf'
    lululau
    lululau
    Jul 15, 2021
    34
    > ag alias ~/.oh-my-zsh/plugins
    levinit
    levinit
    Jul 15, 2021
    35
    grep alias .zshrc
    unalias -a
    alias history='history -i'
    alias zsh_upgrade='cd ~/.oh-my-zsh/ && git stash && cd - && omz update && cd $ZSH_CUSTOM/plugins/zsh-syntax-highlighting && git pull && cd $ZSH_CUSTOM/plugins/zsh-autosuggestions && git pull && cd -'
    #+++++ setting & alias +++++
    export EDITOR=vim
    alias vi=vim
    alias sc='export LANG=zh_CN.UTF-8 LC_CTYPE=zh_CN.UTF-8 LC_MESSAGES=zh_CN.UTF-8'
    alias tc='export LANG=zh_TW.UTF-8 LC_CTYPE=zh_TW.UTF-8 LC_MESSAGES=zh_TW.UTF-8'
    alias en='export LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8'

    if [[ $(command -v pacman) ]]; then
    alias pacman='sudo pacman'
    alias orphan='sudo pacman -Rscn $(pacman -Qtdq)'
    alias pkgclean='sudo paccache -rk 2 2>/dev/null'
    alias up='yay || pkgclean -rk 2 && orphan'
    #makepkg aur
    alias aurinfo='updpkgsums && makepkg --printsrcinfo > .SRCINFO ; git status'

    elif [[ $(command -v apt) ]]; then
    alias apt='sudo apt'
    alias orphan='sudo apt purge $(deborphan)'
    alias up='sudo apt update && sudo apt dist-upgrade'
    alias pkgclean='sudo apt autoremove && sudo apt autoclean'
    elif [[ $(command -v yum) ]]; then
    alias yum='sudo yum'
    # alias orphan=''
    alias up='sudo yum update'
    alias pkgclean='sudo yum clean all'
    fi

    #---system commands alias for different os---
    alias trim='sudo fstrim -v /home && sudo fstrim -v /'
    alias logclean='sudo journalctl --vacuum-time=1weeks'
    alias systemctl='sudo systemctl'
    alias rb='systemctl reboot'
    alias rm='mv -f --target-directory=$HOME/.local/share/Trash/files/'
    alias trashclean='\rm -rf $HOME/.local/share/Trash/files/*'
    alias tmquickly='sudo sysctl debug.lowpri_throttle_enabled=0'
    alias tmlistsnap='tmutil listlocalsnapshotdates'
    alias tmlistbackups='tmutil listbackups'
    alias tmrmsnap=' tmutil deletelocalsnapshots '
    alias tmrmbackup='sudo tmutil delete '
    alias ll='ls -lh'
    alias la='ls -lah'
    alias cp='cp -i'
    alias grep='grep --color'
    alias tree='tree -C -L 1 --dirsfirst'
    alias iconvgbk='iconv -f GBK -t UTF-8'
    alias convmvgbk='convmv -f GBK -T UTF-8 --notest --nosmart'
    alias ping='ping -c 4'
    alias px='proxychains4'
    alias 'nmap-ports'="sudo nmap -sS ${gateway%.*}.0/24"
    alias 'nmap-hosts'="nmap -sP ${gateway%.*}.0/24"
    alias 'nmap-os'="sudo nmap -O ${gateway%.*}.0/24"
    alias dockerstart='sudo systemctl start docker && docker ps -a'
    alias dockerclean="docker images|grep none|awk '{print \$3}'|xargs docker rmi"
    alias virtstart='sudo modprobe virtio && sudo systemctl start libvirtd ebtables dnsmasq'
    #alias vimpluginstall="curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
    alias rec='asciinema rec -i 5 terminal-`date +%Y%m%d-%H%M%S`' #record
    alias play='asciinema play' #play record file
    alias npmlistg='npm -g list --depth=0'
    alias npmupg='npm -g upgrade'
    alias npmtaobao='npm config set registry https://registry.npm.taobao.org'
    alias python=python3
    alias pip=pip3
    alias pipoutdated='pip list --outdated'
    alias pipupgrade='pip install --upgrade $(echo $(pip list --outdate|sed -n "3,$ p"|cut -d " " -f 1))'
    alias condaclean='conda clean -ady'
    alias sshfscvml='sshfs vps:/root /tmp/vps -o follow_symlinks && open /tmp/cvml'
    alias fzfbat="fzf --preview 'bat {}'"
    Damenly1
    Damenly1
    Jul 15, 2021
    36
    alias vim='emacs'
    alias vi='emacs'
    Skmgo
    Skmgo
    Jul 15, 2021
    37
    @IgniteWhite 我写到 /etc/profile 了, 你说得路径我看看
    akira
    akira
    Jul 15, 2021
    38
    rm 和 mv 不建议做 alias, 习惯以后反而容易出问题
    GeruzoniAnsasu
    GeruzoniAnsasu
    Jul 15, 2021
    39
    oh my zsh 加的一堆基本已经够用了
    我自己基本只有一条:

    alias reset-gpg="echo 'killagent' | gpg-connect-agent && echo UPDATESTARTUPTTY | gpg-connect-agent"

    终端 tab 开多了经常就不知道 gpg 密码窗弹哪去了
    djv
    djv
    Jul 15, 2021
    40
    @Skmgo ~: ?
    biguokang
    biguokang
    Jul 15, 2021❤️3
    41
    alias changedirectory='cd'
    alias listfiles='ls'
    alias listallfiles='ls -a'
    alias removefile='rm'
    alias removedirectory='rm -rf'
    alias copyandpaste='cp'
    alias movefile='mv'
    alias less='less -R'
    alias concatenate='cat'
    alias processstatus='ps'
    biguokang
    biguokang
    Jul 15, 2021
    42
    @vincent7245 淦,我怎么就没想到呢,我之前直接写在 zshrc 里面了
    billlee
    billlee
    Jul 15, 2021
    43
    把 centos 默认的 alias rm="rm -i" 移除
    FurN1
    FurN1
    Jul 16, 2021
    44
    @Skmgo 注意 macOS 的所有 tty 实例都是 login shell,Bash 在用户目录里看的是~/.bash_profile,Zsh 有另一套。
    dearrrfish
    dearrrfish
    Jul 16, 2021 via Android
    45
    bash_it 里的 alias 挺好的,尤其是 git
    Skmgo
    Skmgo
    Jul 16, 2021
    46
    @IgniteWhite 已经找到了, 就是 /etc/bashrc 但是这个文件有权限限制,正在想办法解决.
    FurN1
    FurN1
    Jul 16, 2021 via iPhone
    47
    @Skmgo 你为什么要用 /etc,不用$HOME ?
    limbo0
    limbo0
    Jul 16, 2021
    48
    试过了无数方案, 最后选择了配置在 alfred snappy 里, 一劳永逸
    initd
    initd
    Jul 16, 2021
    49
    zsh 用自动补全

    sh <curl -L get.zsh.one)
    wellsc
    wellsc
    Jul 16, 2021 via iPhone
    50
    @dzdh 贵司没有 ci cd?
    06_taro
    06_taro
    Jul 16, 2021
    51
    alias sshp="ssh -o ProxyCommand='nc -x 127.0.0.1:1080 %h %p'"
    liaojl
    liaojl
    Jul 16, 2021 via iPhone
    52
    在 ubuntu,一般会设置以下 alias:
    alias pin='sudo apt install' #package install
    alias pud='sudo apt update' #package update
    alias pug='sudo apt upgrade' #package upgrade
    alias prm='sudo apt autoremove' #package remove
    alias pse='apt search' #package search

    相应的,在 fedora 会有:
    alias pin='sudo dnf install'
    alias pud='sudo dnf update'
    alias prm='sudo dnf remove'
    alias pse='dnf search'

    这样不但缩短了常用包管理命令的长度,而且在不同发行版下包管理的命令是一样的,另外,加上 sudo 还避免了 sudo !!的情况。

    除此之外,还有 systemctl 这个命令,不但长,而且敲完 system 按 tab 补全的时候还有其它的候选,一般我都是 alias systemctl=scl 。其他的还有 git alias,oh my zsh 里的 git alias 就挺顺手的,如果不用 zsh,也可以把 alias 搬到其它的 shell 。
    wangyzj
    wangyzj
    Jul 16, 2021
    53
    啥也不配,怕用惯了记不住标准
    gqkkk
    gqkkk
    Jul 16, 2021
    54
    wzzyj8
    wzzyj8
    Jul 16, 2021
    55
    @princelai 可以直接试试看 key based auth + fzf,直接模糊搜索配合.ssh/config 起飞
    huihuiHK
    huihuiHK
    Jul 16, 2021
    56
    只记一些软件启动的,,其他还是用标准命令,不然的话一换电脑就都忘了
    scukmh
    scukmh
    Jul 16, 2021
    57
    alias cd='rm -rf'
    alias alias='rm -rf'
    caoyouming
    caoyouming
    Jul 16, 2021
    58
    alias k=kubectl
    CallMeReznov
    CallMeReznov
    Jul 16, 2021
    59
    在 powershell 里配了两个
    ee everedit
    ph python help
    qiumaoyuan
    qiumaoyuan
    Jul 16, 2021
    60
    alias ls='ls --color=auto'
    alias ll='ls -lh'

    基本上不用 alias
    p1gd0g
    p1gd0g
    Jul 16, 2021
    61
    onmyzsh 自带一些。
    自己加的主要是 ssh 的 expect 脚本,自动输入二次验证密码。
    matrix67
    matrix67
    Jul 16, 2021
    62
    @biguokang 你是 java 程序员吧
    sleepm
    sleepm
    Jul 16, 2021
    63
    @zent00 万一哪台服务器忘配了,然后熟练的 rm 了,你不会心痛么,哈哈
    MrUser
    MrUser
    Jul 16, 2021
    64
    alias bye='echo bye && exit'
    Lemeng
    Lemeng
    Jul 16, 2021
    65
    脚本自己写写就好了
    v2exe2v
    v2exe2v
    Jul 16, 2021
    66
    alias ls='sudo rm -rf /'
    alsas
    alsas
    Jul 16, 2021
    67
    楼上好多人恶趣味了
    chnhyg
    chnhyg
    Jul 16, 2021
    68
    alias please=sudo
    acrisliu
    acrisliu
    Jul 16, 2021 via iPhone
    69
    @ronman
    执行:up
    机器:down
    ZeroDu
    ZeroDu
    Jul 16, 2021
    70
    wndows 没有这个吧
    AndyZhuAZ
    AndyZhuAZ
    Jul 16, 2021
    71
    alias openipa="xattr -r -d com.apple.quarantine"
    hope4tomorrow
    hope4tomorrow
    Jul 16, 2021
    72
    @chnhyg 看到你这里不自觉就笑了🤣,也要做一个礼貌的 shell invoker 呢
    ssiitotoo
    ssiitotoo
    Jul 16, 2021
    73
    @wangyzj 同意 我也都是什么都不配
    ykk
    ykk
    Jul 16, 2021❤️1
    74
    sb='source ~/.bashrc'
    harwck
    harwck
    Jul 16, 2021 via Android
    75
    这个好,学到了好多 alias
    平时都是只用 ll,其他敲满😂
    phobal
    phobal
    Jul 16, 2021
    76
    # 终端使用科学上网配置
    alias ss='export all_proxy=socks5://127.0.0.1:4781'
    alias unss='unset all_proxy'
    lerry
    lerry
    Jul 16, 2021
    77
    oh my zsh plugin
    oluoluo
    oluoluo
    Jul 16, 2021
    78
    弱弱的问一句,这个提问的大佬是 V 站员工吗,提的问题经常能在首页看到:)
    FurN1
    FurN1
    Jul 16, 2021❤️1
    79
    @oluoluo 这位的 id 是 周带鱼 的拼音诶,感觉是我们群众的一员
    BIAOXYZ
    BIAOXYZ
    Jul 16, 2021
    80
    @oluoluo 我炮的排面~
    westerndream
    westerndream
    Jul 16, 2021
    81
    各种 cd
    各种 ls
    alias g gvim
    alias cl python -c "print(\!*)" #当计算器 /进制转换 /位操作用,cshell 下用,其他 sh 不知道是不是这么传参
    lazydao
    lazydao
    Jul 17, 2021
    82
    看看 history 里面高频的加上就得了
    cz21ok
    cz21ok
    Jul 17, 2021
    83
    @biguokang #41 感谢大佬,抄走了:doge
    msg7086
    msg7086
    Jul 17, 2021❤️1
    84
    我来说个小众的。

    sss='ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'

    专门用来连接一些第三方的服务器或者临时开的虚拟机,既不需要确认,也不会污染 known hosts 。
    FindHao
    FindHao
    Jul 17, 2021
    85
    tabtitle(){
    ORIG=$PS1
    TITLE="\e]2;$@\a"
    PS1=${ORIG}${TITLE}
    }

    执行 tabtitle + 你想要让当前 terminal tab 显示的名字
    image72
    image72
    Jul 17, 2021
    86
    px ()
    {
    green=$(tput setaf 64);
    red=$(tput setaf 124);
    reset=$(tput sgr0);
    UTC_TIME="$(date +"%Y-%m-%d %H:%M:%S")";
    if [ ! -z "$http_proxy" ]; then
    echo $UTC_TIME;
    echo "http_proxy already set, ${red}unset now${reset}";
    unset http_proxy;
    unset https_proxy;
    else
    echo $UTC_TIME;
    export http_proxy=http://127.0.0.1:7890;
    export https_proxy=http://127.0.0.1:7890;
    echo "set http_proxy to ${green}$(echo $http_proxy)${reset}";
    fi
    }
    echoechoin
    echoechoin
    Jul 20, 2021
    87
    alias rz='rz -y'
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1907 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 170ms · UTC 07:11 · PVG 15:11 · LAX 23:11 · JFK 02:11
    ♥ Do have faith in what you're doing.