生产实践:
常用alias提高工作效率,可按需添加
使用技巧:
在~目录下创建.bash_aliases,在/etc/profile添加 [[ -f ~/.bash_aliases ]] && source ~/.bash_aliases 内容
文件内容:
alias vps='ssh -p xxx root@xxxxxx' alias egrep='egrep --color' alias fgrep='fgrep --color' alias vi='vim' alias rm='rm -i' alias mv='mv -i' alias cp='cp -i' alias glg='git lg' alias mysqlstart='/usr/local/Cellar/mysql/5.7.20/bin/mysql.server start' alias mysqlstop='/usr/local/Cellar/mysql/5.7.20/bin/mysql.server stop' alias mysqlrestart='/usr/local/Cellar/mysql/5.7.20/bin/mysql.server restart' alias wl='ll | wc -l' alias lh='ls -lah' alias c='clear' # 快速清屏 alias p='pwd' alias dps='docker ps' alias dpsa='docker ps -a' # 进入目录并列出文件,如 cdl ../conf.d/ cdl() { cd "$@" && pwd ; ls -alF; } alias ..="cdl .." alias ...="cd ../.." # 快速进入上上层目录 alias .3="cd ../../.." alias cd..='cdl ..' # alias cp="cp -iv" # interactive, verbose # alias mv="mv -iv" # interactive, verbose alias psg='\ps aux | grep -v grep | grep --color' # 查看进程信息 alias hg='history|grep' alias netp='netstat -tulanp' # 查看服务器端口连接信息 alias lvim="vim -c \"normal '0\"" # 编辑vim最近打开的文件 alias tf='tail -f ' # 快速查看文件末尾输出 # 自动在文件末尾加上 .bak-日期 来备份文件,如 bu nginx.conf bak() { cp "$@" "$@.bak"-`date +%y%m%d`; echo "`date +%Y-%m-%d` backed up $PWD/$@"; } # 级联创建目录并进入,如 mcd a/b/c mcd() { mkdir -p $1 && cd $1 && pwd ; } # 查看去掉#注释和空行的配置文件,如 nocomm /etc/squid/squid.conf alias nocomm='grep -Ev '\''^(#|$)'\''' # 快速根据进程号pid杀死进程,如 psid tomcat, 然后 kill9 两个tab键提示要kill的进程号 alias kill9='kill -9'; psid() { [[ ! -n ${1} ]] && return; # bail if no argument pro="[${1:0:1}]${1:1}"; # process-name –> [p]rocess-name (makes grep better) ps axo pid,user,command | grep -v grep |grep -i --color ${pro}; # show matching processes pids="$(ps axo pid,user,command | grep -v grep | grep -i ${pro} | awk '{print $1}')"; # get pids complete -W "${pids}" kill9 # make a completion list for kk } # 解压所有归档文件工具 function extract { if [ -z "$1" ]; then # display usage if no parameters given echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>" else if [ -f $1 ] ; then # NAME=${1%.*} # mkdir $NAME && cd $NAME case $1 in *.tar.bz2) tar xvjf $1 ;; *.tar.gz) tar xvzf $1 ;; *.tar.xz) tar xvJf $1 ;; *.lzma) unlzma $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar x -ad $1 ;; *.gz) gunzip $1 ;; *.tar) tar xvf $1 ;; *.tbz2) tar xvjf $1 ;; *.tgz) tar xvzf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1 ;; *.7z) 7z x $1 ;; *.xz) unxz $1 ;; *.exe) cabextract $1 ;; *) echo "extract: '$1' - unknown archive method" ;; esac else echo "$1 - file does not exist" fi fi }