main.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. ##############################################################################
  2. #
  3. # Generic Commands
  4. #
  5. ##############################################################################
  6. alias ..='cd ..'
  7. alias h='cd ~'
  8. alias isodate='date -u +"%Y-%m-%dT%H:%M:%SZ"'
  9. alias tsp="ts '[%Y-%m-%dT%H:%M:%S:%SZ]'" # prepend an iso timestamp (requires moreutils)
  10. alias as_super='sudo $(fc -ln -1)' # Rerun last command w/ sudo
  11. alias yolo=as_super
  12. alias please=as_super
  13. alias become_root='sudo su -'
  14. alias become_death=become_root
  15. alias top_commands="cut -f1 -d\" \" .bash_history | sort | uniq -c | sort -nr | head -n 30"
  16. alias get_url="grep -Eo \"(http|https)://[\da-z./?A-Z0-9\D=_-]*\""
  17. alias awk1="awk '{print \$1}'"
  18. alias awk2="awk '{print \$2}'"
  19. alias awk3="awk '{print \$3}'"
  20. alias awklast="rev | awk1 | rev"
  21. alias fthr="numfmt --to=iec-i --suffix=B --padding=7"
  22. function audio-log {
  23. sox -d audio-log-`isodate`.ogg
  24. }
  25. function killit {
  26. ps aux | grep -i "$1" | grep -v "grep" | awk2 | xargs kill ${@:2:99}
  27. }
  28. function largefiles() {
  29. du -k $1 2>/dev/null | awk '$1 > 1000000' | sort -nr | awk -F' ' '{ print system("numfmt --to=iec-i --suffix=B -z --padding=7 " $1 * 1000) " " $2 }'
  30. }
  31. export ROME=$PATH:$PYTHONPATH:$CLASSPATH:$ORACLEPATH:$FOOPATH:$LOLPATH:$YOLOPATH:$(which python)
  32. function gpid() {
  33. ps aux | grep "$1" | grep -v grep | awk '{print $2}'
  34. }
  35. function grkill() {
  36. if [ -z "$1" ]; then
  37. echo "no match string provided";
  38. return 1;
  39. fi
  40. kill `gpid $1`
  41. }
  42. # Keep stuff out of history
  43. function offrecord() {
  44. fc -p;
  45. }
  46. function onrecord() {
  47. fc -P;
  48. }
  49. # Make a directory and cd into it
  50. function mkcdir() {
  51. mkdir -p -- "$1" && cd -P -- "$1"
  52. }
  53. # Start a screen
  54. function start-screen () {
  55. if ! screen -x main -q; then
  56. screen -S main
  57. fi
  58. }
  59. alias sts='start-screen';
  60. # Watch and record
  61. function watch-and-record () {
  62. while true
  63. do
  64. ${@:3} 2>&1 | tee -a "$2"
  65. sleep $1
  66. done
  67. }
  68. function find_large_folders() {
  69. du -hS / | perl -ne '(m/\d{${$1-3},}M\s+\S/ || m/G\s+\S/) && print'
  70. }
  71. function find_large_files() {
  72. find ./ -size +$1M -type f -print0 | xargs -0 ls -Ssh1 --color
  73. }
  74. function compress_()
  75. {
  76. TYPE=$2
  77. SIZE=`du -sk "$1" | cut -f 1`
  78. case $TYPE in
  79. "tar.bz2") tar cvf - "$1" | pv -p -s ${SIZE}k | bzip2 -c > "$1".tar.bz2 ;;
  80. "tar.gz") tar cvf - "$1" | pv -p -s ${SIZE}k | gzip -c > "$1".tar.gz ;;
  81. "tgz") tar cvf - "$1" | pv -p -s ${SIZE}k | gzip -c > "$1".tgz ;;
  82. "zip") zip -r - "$1" | pv -p -s ${SIZE}k > "$1".zip ;;
  83. "rar") rar $FILE $* ;;
  84. *) echo "Filetype not recognized" ;;
  85. esac
  86. }
  87. ##### create dated tarball
  88. function tarball()
  89. {
  90. name=$1
  91. shift
  92. tar zcvf $name-`date +%Y%m%d`.tar.gz "$@"
  93. }
  94. function loc() {
  95. find . -name "*.${1:-py}" | xargs wc -l
  96. }
  97. # URL encode/decode
  98. alias urldecode='python -c "import sys, urllib as ul; print ul.unquote_plus(sys.argv[1])"'
  99. alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1])"'
  100. # Get my IP
  101. function myip () {
  102. wget http://ipinfo.io/ip -qO -;
  103. }
  104. #
  105. # Nmap stuff
  106. #
  107. # Get ssh host
  108. function nmap_ssh_host_keys() {
  109. nmap -p 22 --script ssh-hostkey -v $1 -Pn
  110. }
  111. function nmap_host_os() {
  112. sudo nmap -O -v $1
  113. }
  114. function nmap_scan_port() {
  115. sudo nmap -p $2 $1
  116. }
  117. function md5dir {
  118. find -s "$1" -type f -exec md5 {} \; | md5
  119. }
  120. function f2f {
  121. for file in *.$1; do
  122. mv -- "$file" "$(basename -- "$file" .$1).$2"
  123. done
  124. }