bash alias 配置

bash 命令的一些快捷配置,可以在 .bashrc 等文件里直接加上 source /etc/profile.d/alias.sh。(我的github上的gist里也有)

# /etc/profile.d/alias.sh

# https://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html

## ls command
alias ls='ls --color=auto'
alias wl='ls | wc -l'
alias l='ls -l --color=auto'
alias lh='ls -lh --color=auto'
alias ll='ls -la --color=auto'  # use a long listing format
alias l.='ls -d .* --color=auto'  # show hidden files

## cd command
alias cd..='cd ..'
alias ..='cd ..'

## colorize the grep command output for ease of use
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'

## start calculator with math support
alias bc='bc -l'

# sudo apt install colordiff
alias diff='colordiff'

# make mount command output pretty and human readable format
alias mount='mount |column -t'

# handy short cuts #
alias h='history'
alias j='jobs -l'
alias c='clear'
alias p='pwd'

alias path='echo -e ${PATH//:/\\n}'  # print paths in $PATH
alias nowtime='date +"%T"'
alias nowdate='date +"%Y-%m-%d"'

## set vim as default
alias edit='vim'

## use netstat command to quickly list all TCP/UDP port on the server
alias ports='netstat -tulanp'

## control firewall (iptables) output
# https://www.cyberciti.biz/tips/linux-iptables-examples.html

# shortcut for iptables and pass it via sudo
alias ipt='sudo /sbin/iptables'

# display all rules
alias iptlist='sudo /sbin/iptables -L -n -v --line-numbers'
alias iptlistin='sudo /sbin/iptables -L INPUT -n -v --line-numbers'
alias iptlistout='sudo /sbin/iptables -L OUTPUT -n -v --line-numbers'
alias iptlistfw='sudo /sbin/iptables -L FORWARD -n -v --line-numbers'
alias firewall=iptlist

## add safety cp/mv/rm
# alias rm="rm -i"
# alias mv='mv -iv'
# alias cp='cp -iv'
# alias ln='ln -i'

## get system memory, cpu usage, and gpu memory info quickly
# memory info
alias meminfo='free -m -l -t'

# get top process eating memory
alias psmem='ps auxf | sort -nr -k 4'
alias psmem10='ps auxf | sort -nr -k 4 | head -10'

# get top process eating cpu ##
alias pscpu='ps auxf | sort -nr -k 3'
alias pscpu10='ps auxf | sort -nr -k 3 | head -10'

# get server cpu info ##
alias cpuinfo='lscpu'

# get GPU ram on desktop / laptop##
alias gpumeminfo='grep -i --color memory /var/log/Xorg.0.log'

## Resume wget by default
alias wget='wget -c'

## tail -f
alias tailf='tail -f'

## backup util.
function bak() {
  cp "$@" "$@.bak"-`date +%y%m%d`;
  echo "`date +%Y-%m-%d-%s` backed up $PWD/$@";
}

alias kill9='kill -9'

## extract util.
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
}

# Usage: psfind <keywords> (RegExp supported)
function psfind() {
  ps aux | head -n 1
  ps aux | grep -E $1 | grep -v grep
}

# feh
alias feh_full='feh -F --keep-zoom-vp -d'