123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- ##############################################################################
- #
- # Generic Commands
- #
- ##############################################################################
- alias ..='cd ..'
- alias h='cd ~'
- alias isodate='date -u +"%Y-%m-%dT%H:%M:%SZ"'
- alias tsp="ts '[%Y-%m-%dT%H:%M:%S:%SZ]'" # prepend an iso timestamp (requires moreutils)
- alias as_super='sudo $(fc -ln -1)' # Rerun last command w/ sudo
- alias yolo=as_super
- alias please=as_super
- alias become_root='sudo su -'
- alias become_death=become_root
- alias top_commands="cut -f1 -d\" \" .bash_history | sort | uniq -c | sort -nr | head -n 30"
- alias get_url="grep -Eo \"(http|https)://[\da-z./?A-Z0-9\D=_-]*\""
- alias awk1="awk '{print \$1}'"
- alias awk2="awk '{print \$2}'"
- alias awk3="awk '{print \$3}'"
- alias awklast="rev | awk1 | rev"
- alias fthr="numfmt --to=iec-i --suffix=B --padding=7"
- function audio-log {
- sox -d audio-log-`isodate`.ogg
- }
- function killit {
- ps aux | grep -i "$1" | grep -v "grep" | awk2 | xargs kill ${@:2:99}
- }
- function largefiles() {
- 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 }'
- }
- export ROME=$PATH:$PYTHONPATH:$CLASSPATH:$ORACLEPATH:$FOOPATH:$LOLPATH:$YOLOPATH:$(which python)
- function gpid() {
- ps aux | grep "$1" | grep -v grep | awk '{print $2}'
- }
- function grkill() {
- if [ -z "$1" ]; then
- echo "no match string provided";
- return 1;
- fi
- kill `gpid $1`
- }
- # Keep stuff out of history
- function offrecord() {
- fc -p;
- }
- function onrecord() {
- fc -P;
- }
- # Make a directory and cd into it
- function mkcdir() {
- mkdir -p -- "$1" && cd -P -- "$1"
- }
- # Start a screen
- function start-screen () {
- if ! screen -x main -q; then
- screen -S main
- fi
- }
- alias sts='start-screen';
- # Watch and record
- function watch-and-record () {
- while true
- do
- ${@:3} 2>&1 | tee -a "$2"
- sleep $1
- done
- }
- function find_large_folders() {
- du -hS / | perl -ne '(m/\d{${$1-3},}M\s+\S/ || m/G\s+\S/) && print'
- }
- function find_large_files() {
- find ./ -size +$1M -type f -print0 | xargs -0 ls -Ssh1 --color
- }
- function compress_()
- {
- TYPE=$2
- SIZE=`du -sk "$1" | cut -f 1`
- case $TYPE in
- "tar.bz2") tar cvf - "$1" | pv -p -s ${SIZE}k | bzip2 -c > "$1".tar.bz2 ;;
- "tar.gz") tar cvf - "$1" | pv -p -s ${SIZE}k | gzip -c > "$1".tar.gz ;;
- "tgz") tar cvf - "$1" | pv -p -s ${SIZE}k | gzip -c > "$1".tgz ;;
- "zip") zip -r - "$1" | pv -p -s ${SIZE}k > "$1".zip ;;
- "rar") rar $FILE $* ;;
- *) echo "Filetype not recognized" ;;
- esac
- }
- ##### create dated tarball
- function tarball()
- {
- name=$1
- shift
- tar zcvf $name-`date +%Y%m%d`.tar.gz "$@"
- }
- function loc() {
- find . -name "*.${1:-py}" | xargs wc -l
- }
- # URL encode/decode
- alias urldecode='python -c "import sys, urllib as ul; print ul.unquote_plus(sys.argv[1])"'
- alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1])"'
- # Get my IP
- function myip () {
- wget http://ipinfo.io/ip -qO -;
- }
- #
- # Nmap stuff
- #
- # Get ssh host
- function nmap_ssh_host_keys() {
- nmap -p 22 --script ssh-hostkey -v $1 -Pn
- }
- function nmap_host_os() {
- sudo nmap -O -v $1
- }
- function nmap_scan_port() {
- sudo nmap -p $2 $1
- }
- function md5dir {
- find -s "$1" -type f -exec md5 {} \; | md5
- }
- function f2f {
- for file in *.$1; do
- mv -- "$file" "$(basename -- "$file" .$1).$2"
- done
- }
|