Advertisement
osteth

bash_aliases

Jun 28th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.54 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #Set Nano as default editor
  4. export EDITOR=nano
  5.  
  6. #Force Python3
  7. alias python="python3"
  8. alias pip='pip3'
  9.  
  10. #Sylization Aliases
  11. #########################################
  12. ## Colorize the ls output ##
  13. alias ls='ls --color=auto'
  14.  
  15. ## Show hidden files ##
  16. alias l.='ls -d .* --color=auto'
  17.  
  18. ## Colorize the grep command output for ease of use (good for log files)##
  19. alias grep='grep --color=auto'
  20. alias egrep='egrep --color=auto'
  21. alias fgrep='fgrep --color=auto'
  22.  
  23. ##install colordiff package :) ##
  24. alias diff='colordiff'
  25.  
  26. ##Prety Print mount output ##
  27. alias mount='mount |column -t'
  28.  
  29. #Misstype Correctors
  30. #########################################
  31.  
  32. ## get rid of command not found ##
  33. alias cd..='cd ..'
  34. alias sl='ls'
  35. alias pdw="pwd"
  36.  
  37. #Easy Directory Traversal ++
  38. ##########################################
  39.  
  40. ## a quick way to get out of current directory ##
  41. alias ..='cd ..'
  42. alias ...='cd ../../../'
  43. alias ....='cd ../../../../'
  44. alias .....='cd ../../../../'
  45. alias ......='cd ../../../../'
  46. alias .......='cd ../../../../..'
  47.  
  48. ## Use a long listing format ##
  49. alias ll='ls -la'
  50.  
  51. #Ease of use Aliases
  52. ##############################################
  53.  
  54. ##Create parent directories on demand##
  55. alias mkdir='mkdir -pv'
  56.  
  57. ## tAdds continue flag to continue downloads in case of network interuptions. ##
  58. alias wget='wget -c'
  59.  
  60. ## set some other defaults ##
  61. alias df='df -H'
  62. alias du='du -ch'
  63.  
  64. # share history between terminal sessions
  65. alias he="history -a" # export history
  66. alias hi="history -n" # import history
  67.  
  68. # pipe ps aux to grep. Use: psg java
  69. #alias psg="ps aux | grep -v grep | grep -i -e VSZ -e"
  70.  
  71. #paste thing to termbin.com (use: echo test | tb)
  72. alias tb="nc termbin.com 9999"
  73.  
  74. #System Information Aliases
  75. #############################################
  76.  
  77. ## pass options to free ##
  78. alias meminfo='free -m -l -t'
  79.  
  80. ## get top process eating memory
  81. alias psmem='ps auxf | sort -nr -k 4'
  82. alias psmem10='ps auxf | sort -nr -k 4 | head -10'
  83.  
  84. ## get top process eating cpu ##
  85. alias pscpu='ps auxf | sort -nr -k 3'
  86. alias pscpu10='ps auxf | sort -nr -k 3 | head -10'
  87.  
  88. ## Get server cpu info ##
  89. alias cpuinfo='lscpu'
  90.  
  91. ## older system use /proc/cpuinfo ##
  92. alias cpuinfo='less /proc/cpuinfo'
  93.  
  94. ## get GPU ram on desktop / laptop##
  95. alias gpumeminfo='grep -i --color memory /var/log/Xorg.0.log'
  96.  
  97. #Extra Commands and Command Shortcuts
  98. #############################################
  99.  
  100. # handy short cuts #
  101. alias h='history'
  102. alias j='jobs -l'
  103. alias path='echo -e ${PATH//:/\\n}'
  104. alias now='date +"%T"'
  105. alias nowtime='now'
  106. alias nowdate='date +"%d-%m-%Y"'
  107.  
  108. #copy output of last command to clipboard
  109. alias cl="fc -e -|pbcopy"
  110.  
  111. # copy the working directory path
  112. alias cpwd='pwd|tr -d "\n"|pbcopy'
  113.  
  114. # Frees up the cached memory
  115. alias freemem='sync && echo 3 | sudo tee /proc/sys/vm/drop_caches'
  116.  
  117. #Networking Controls
  118. #################################################
  119.  
  120. # Get your current public IP
  121. alias ip="curl icanhazip.com"
  122.  
  123. # Stop after sending count ECHO_REQUEST packets #
  124. alias ping='ping -c 5'
  125.  
  126. # Do not wait interval 1 second, go fast #
  127. alias fastping='ping -c 100 -s.2'
  128.  
  129. ##Show Open Ports##
  130. alias ports='netstat -tulanp'
  131.  
  132. ## shortcut for iptables and pass it via sudo#
  133. alias ipt='sudo /sbin/iptables'
  134.  
  135. ## display all rules ##
  136. alias iptlist='sudo /sbin/iptables -L -n -v --line-numbers'
  137. alias iptlistin='sudo /sbin/iptables -L INPUT -n -v --line-numbers'
  138. alias iptlistout='sudo /sbin/iptables -L OUTPUT -n -v --line-numbers'
  139. alias iptlistfw='sudo /sbin/iptables -L FORWARD -n -v --line-numbers'
  140. alias firewall='iptlist'
  141.  
  142. ## All of our servers eth1 is connected to the Internets via vlan / router etc ##
  143. alias dnstop='dnstop -l 5 eth1'
  144. alias vnstat='vnstat -i eth1'
  145. alias iftop='iftop -i eth1'
  146. alias tcpdump='tcpdump -i eth1'
  147. alias ethtool='ethtool eth1'
  148.  
  149. # work on wlan0 by default # Only useful for laptop as all servers are without wireless interface
  150. alias iwconfig='iwconfig wlan0'
  151.  
  152. #Safety Nets (Dont Break Your Machine!)
  153. #################################################
  154. # do not delete / or prompt if deleting more than 3 files at a time #
  155. alias rm='rm -I --preserve-root'
  156.  
  157. # confirmation #
  158. alias mv='mv -i'
  159. alias cp='cp -i'
  160. alias ln='ln -i'
  161.  
  162. # Parenting changing perms on / #
  163. alias chown='chown --preserve-root'
  164. alias chmod='chmod --preserve-root'
  165. alias chgrp='chgrp --preserve-root'
  166.  
  167. #File Manipulation Aliases
  168. #########################################
  169.  
  170. # trim newlines
  171. alias tn='tr -d "\n"'
  172.  
  173. ##optimize images for web using imagemacick to reduce the mo 690px
  174. #(apt-get install imagemagick) if this fails.
  175. alias webify="mogrify -resize 690\> *.png"
  176.  
  177. #Functions
  178. ########################################
  179.  
  180. ### Get os name via uname ###
  181. _myos="$(uname)"
  182.  
  183. ### add alias as per os using $_myos ###
  184. case $_myos in
  185.    Linux) alias foo='/path/to/linux/bin/foo';;
  186.    FreeBSD|OpenBSD) alias foo='/path/to/bsd/bin/foo' ;;
  187.    SunOS) alias foo='/path/to/sunos/bin/foo' ;;
  188.    *) ;; esac
  189.  
  190. function extract {
  191.  if [ -z "$1" ]; then
  192.     # display usage if no parameters given
  193.     echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
  194.  else
  195.     if [ -f "$1" ] ; then
  196.         # NAME=${1%.*} mkdir $NAME && cd $NAME
  197.         case $1 in
  198.           *.tar.bz2) tar xvjf ../"$1" ;;
  199.           *.tar.gz) tar xvzf ../"$1" ;;
  200.           *.tar.xz) tar xvJf ../"$1" ;;
  201.           *.lzma) unlzma ../"$1" ;;
  202.           *.bz2) bunzip2 ../"$1" ;;
  203.           *.rar) unrar x -ad ../"$1" ;;
  204.           *.gz) gunzip ../"$1" ;;
  205.           *.tar) tar xvf ../"$1" ;;
  206.           *.tbz2) tar xvjf ../"$1" ;;
  207.           *.tgz) tar xvzf ../"$1" ;;
  208.           *.zip) unzip ../"$1" ;;
  209.           *.Z) uncompress ../"$1" ;;
  210.           *.7z) 7z x ../"$1" ;;
  211.           *.xz) unxz ../"$1" ;;
  212.           *.exe) cabextract ../"$1" ;;
  213.           *) echo "extract: '$1' - unknown archive method" ;;
  214.         esac
  215.     else
  216.         echo "$1 - file does not exist"
  217.     fi fi
  218. }
  219.  
  220. function top10 {
  221.     history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl |  head -n10
  222. }
  223.  
  224.  
  225.  
  226. ####### Begin Uploadfiles.io api aliases #######
  227.  
  228. ufiles() {
  229.     source ~/ufiles.conf
  230.     if [ "$1" != "" ]; then
  231.         if [ "$1" == "put" ]; then
  232.             if [ "$KEY" != "" ]; then
  233.                 if [ "$USER" != "" ]; then
  234.                     if [ "$2" != "" ]; then
  235.                         curl -X POST -F "file=@$2" -F "user_id=$USER" -F "auth_key=$KEY" https://up.uploadfiles.io/upload
  236.                     else
  237.                         echo "No Files was specified for upload"
  238.                         echo "please retry as follows:"
  239.                         echo "ufile put <file to upload>"
  240.                     fi
  241.                 else
  242.                     echo "No User was Specified in ~/ufiles.conf"
  243.                     echo "Please Check your configuration and try again."
  244.         fi
  245.             else
  246.                 echo "No KEY was Specified in ~/ufiles.conf"
  247.                 echo "Please Check your configuration and try again."
  248.             fi
  249.         elif [ "$1" == "get" ]; then
  250.             if [ "$KEY" != "" ]; then
  251.                 if [ "$USER" != "" ]; then
  252.                     if [ "$2" != "" ]; then
  253.                          if [ "$3" != "" ]; then
  254.                             curl -u $USER:$KEY -o $2 https://down.uploadfiles.io/get/$1
  255.                         else
  256.                             curl -u $USER:$KEY -o $1 https://down.uploadfiles.io/get/$1
  257.                         fi
  258.                     else
  259.                         echo "No save path was specified."
  260.                         echo "please retry as follows:"
  261.             echo "ufile get SLUG OPTIONAL SAVE PATH"
  262.                     fi
  263.                 else
  264.                     echo "No User was Specified in ~/ufiles.conf"
  265.                     echo "Please Check your configuration and try again."
  266.                 fi
  267.             else
  268.                 echo "No KEY was Specified in ~/ufiles.conf"
  269.                 echo "Please Check your configuration and try again."
  270.             fi
  271.         elif [ "$1" == "auth" ]; then
  272.         if [ "$2" != "" ]; then
  273.                 if [ "$3" != "" ]; then
  274.                    cat <<EOT > ~/ufiles.conf #!/bin/bash
  275.                    ##This config file store user credentials for using the ufiles-tools bash aliase.
  276.  
  277.                    USER=$2
  278.                    KEY=$3
  279. EOT
  280.                 else
  281.                     echo "Positional arguemnt USER is empty"
  282.                     echo "Please re-try as follows:"
  283.                     echo "ufile auth USER_ID AUTH_KEY"
  284.                 fi
  285.             else
  286.                 echo "Positional argument KEY is empty"
  287.                 echo "Please re-try as follows:"
  288.                 echo "ufile auth USER_ID AUTH_KEY"
  289.             fi
  290.         elif [ "$1" == "--help" ]; then
  291.             echo "Usage: ufile [OPTIONS] COMMAND [ARGS]..."
  292.             echo ""
  293.             echo "This is a command line utility to aid in handling file transfers to and"
  294.             echo "from Uploadfiles.io. Additional information is avilable at"
  295.             echo "https://github.com/osteth/ufile-tools/"
  296.             echo ""
  297.             echo "Options:"
  298.             echo "--help  Show this message and exit."
  299.             echo ""
  300.             echo "Commands:"
  301.             echo "put    Upload a file to Uploadfiles.io"
  302.             echo "get    Download a file from Uploadfiles.io"
  303.             echo "auth   Change your user credentials."
  304.         fi
  305.     else
  306.         echo "fail"
  307.     fi
  308. }
  309.  
  310. ####### End Uploadfiles.io api aliases #######
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement