Posted By

narkisr on 02/06/09


Tagged

Bash aliases


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

scottshane
romulousprime
vthreex
Nix


A long list of bash aliases worth going through


 / Published in: Bash
 

Some nice base aliases, still need to go through them

  1. # _ _ _ __
  2. # ___ | |__ ___ | || | / _| _ _ ___ _ __ __ _
  3. # / __|| '_ \ / _ \| || | _____ | |_ | | | | / _ \| '__|/ _` |
  4. # \__ \| | | | __/| || ||_____|| _|| |_| | _ | (_) | | | (_| |
  5. # |___/|_| |_|\___||_||_| |_| \__,_|(_) \___/|_| \__, |
  6. # .bashrc|___/
  7. #
  8. # If not running interactively, don't do anything
  9. [ -z "$PS1" ] && return
  10.  
  11. # cdpath - http://www.shell-fu.org/lister.php?id=185
  12. export CDPATH='.:~'
  13.  
  14.  
  15. # directory tree - http://www.shell-fu.org/lister.php?id=209
  16. alias dirf='find . -type d | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/|-\1/"'
  17.  
  18.  
  19. #compare files using comm (requires perl) - http://www.shell-fu.org/lister.php?id=186
  20. compare(){
  21. comm $1 $2 | perl -pe 's/^/1: /g;s/1: \t/2: /g;s/2: \t/A: /g;' | sort
  22. }
  23.  
  24.  
  25. #calendar with today highlighted - http://www.shell-fu.org/lister.php?id=210
  26. alias tcal='cal | sed "s/^/ /;s/$/ /;s/ $(date +%e) / $(date +%e | sed '\''s/./#/g'\'') /"'
  27.  
  28.  
  29. # count files by type - http://www.shell-fu.org/lister.php?id=173
  30. alias ftype='find ${*-.} -type f | xargs file | awk -F, '\''{print $1}'\'' | awk '\''{$1=NULL;print $0}'\'' | sort | uniq -c | sort -nr'
  31.  
  32.  
  33. # convert permissions to octal - http://www.shell-fu.org/lister.php?id=205
  34. alias lo='ls -l | sed -e 's/--x/1/g' -e 's/-w-/2/g' -e 's/-wx/3/g' -e 's/r--/4/g' -e 's/r-x/5/g' -e 's/rw-/6/g' -e 's/rwx/7/g' -e 's/---/0/g''
  35.  
  36.  
  37. # portscan in one line - http://www.shell-fu.org/lister.php?id=295
  38. portscan(){
  39. HOST="$1";for((port=1;port<=65535;++port));do echo -en "$port ";if echo -en "open $HOST $port\nlogout\quit" | telnet 2>/dev/null | grep 'Connected to' > /dev/null;then echo -en "\n\nport $port/tcp is open\n\n";fi;done
  40. }
  41.  
  42.  
  43. # print a random shell-fu tip - http://www.shell-fu.org/lister.php?id=192
  44. alias shell-fu='links -dump "http://www.shell-fu.org/lister.php?random" | grep -A 100 -- ----'
  45.  
  46.  
  47. # get an ordered list of subdirectory sizes - http://www.shell-fu.org/lister.php?id=275
  48. alias dux='du -sk ./* | sort -n | awk '\''BEGIN{ pref[1]="K"; pref[2]="M"; pref[3]="G";} { total = total + $1; x = $1; y = 1; while( x > 1024 ) { x = (x + 1023)/1024; y++; } printf("%g%s\t%s\n",int(x*10)/10,pref[y],$2); } END { y = 1; while( total > 1024 ) { total = (total + 1023)/1024; y++; } printf("Total: %g%s\n",int(total*10)/10,pref[y]); }'\'''
  49.  
  50.  
  51. # share current tree over the web - http://www.shell-fu.org/lister.php?id=54
  52. alias webshare='python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"'
  53.  
  54.  
  55. # overwrite a file with zeroes - http://www.shell-fu.org/lister.php?id=94
  56. zero() {
  57. case "$1" in
  58. "") echo "Usage: zero <file>"
  59. return -1;
  60. esac
  61. filesize=`wc -c "$1" | awk '{print $1}'`
  62. dd if=/dev/zero of=$1 count=$filesize bs=1
  63. }
  64.  
  65.  
  66. # keep your home directory organised - http://www.shell-fu.org/lister.php?id=310
  67. export TD="$HOME/temp/`date +'%Y-%m-%d'`"
  68. td(){
  69. td=$TD
  70. if [ ! -z "$1" ]; then
  71. td="$HOME/temp/`date -d "$1 days" +'%Y-%m-%d'`";
  72. fi
  73. mkdir -p $td; cd $td
  74. unset td
  75. }
  76.  
  77.  
  78. # create a terminal calculator - http://www.shell-fu.org/lister.php?id=216
  79. calc(){ echo "${1}"|bc -l; }
  80.  
  81.  
  82. # copy and paste from the command line - http://www.shell-fu.org/lister.php?id=177
  83. ccopy(){ cp $1 /tmp/ccopy.$1; }
  84. alias cpaste="ls /tmp/ccopy* | sed 's|[^\.]*.\.||' | xargs -I % mv /tmp/ccopy.% ./%"
  85.  
  86.  
  87. # bash function to decompress archives - http://www.shell-fu.org/lister.php?id=375
  88. extract () {
  89. if [ -f $1 ] ; then
  90. case $1 in
  91. *.tar.bz2) tar xvjf $1 ;;
  92. *.tar.gz) tar xvzf $1 ;;
  93. *.bz2) bunzip2 $1 ;;
  94. *.rar) unrar x $1 ;;
  95. *.gz) gunzip $1 ;;
  96. *.tar) tar xvf $1 ;;
  97. *.tbz2) tar xvjf $1 ;;
  98. *.tgz) tar xvzf $1 ;;
  99. *.zip) unzip $1 ;;
  100. *.Z) uncompress $1 ;;
  101. *.7z) 7z x $1 ;;
  102. *) echo "'$1' cannot be extracted via >extract<" ;;
  103. esac
  104. else
  105. echo "'$1' is not a valid file"
  106. fi
  107. }
  108.  
  109.  
  110. ######################### Additional Aliases #########################
  111. alias l='ls -alF'
  112. alias ll='ls -alF'
  113. alias dir='ls -la'
  114. alias la='ls -Fa'
  115. alias ld='ls -al -d * | egrep "^d"' # only subdirectories
  116. alias lt='ls -alt | head -20' # recently changed files
  117.  
  118. alias md='mkdir -p'
  119. alias rd=rmdir
  120. alias ..='cd ..'
  121. alias ...='cd ../..'
  122. alias +='pushd .'

Report this snippet  

You need to login to post a comment.