Skip to content

Instantly share code, notes, and snippets.

@insaneyilin
Last active November 19, 2020 13:12
Show Gist options
  • Save insaneyilin/ff96fa7dce0d6e8ccfc46ae6a8f6eb2e to your computer and use it in GitHub Desktop.
Save insaneyilin/ff96fa7dce0d6e8ccfc46ae6a8f6eb2e to your computer and use it in GitHub Desktop.
bash alias
# /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
alias lf='ls -l | grep "^-"' # list files
alias ld='ls -l | grep "^d"' # list directories
alias nrf='ls -l | grep "^-" | wc -l' # number of files
alias nrd='ls -l | grep "^d" | wc -l' # number of directories
## cd command
alias cd..='cd ..'
alias ..='cd ..'
# show
alias show_big_files='du -cks * | sort -rn | head -n 10'
## 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 "$@" "[email protected]"-`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 <keyword> (RegExp supported)
function psfind() {
if [ $# != 1 ] ; then
echo "USAGE: psfind keyword"
echo " e.g.: psfind python3"
else
ps aux | head -n 1
ps aux | grep -E $1 | grep -v grep
fi
}
# Usage: pskillall <keywords> (RegExp supported)
function pskillall() {
if [ $# != 1 ] ; then
echo "USAGE: pskillall keyword"
echo " e.g.: pskillall python3"
else
ps -ef | grep $1 | grep -v grep | awk '{print $2}' | xargs kill -9
fi
}
# feh
alias feh_full='feh -F --keep-zoom-vp -d'
alias showcursor='echo -e "\033[?25h"'
alias hidecursor='echo -e "\033[?25l"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment