daily pastebin goal
27%
SHARE
TWEET

bash_aliases

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