Skip to content

Instantly share code, notes, and snippets.

@aa21
Last active May 3, 2016 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aa21/0bf778f45e21de24c475 to your computer and use it in GitHub Desktop.
Save aa21/0bf778f45e21de24c475 to your computer and use it in GitHub Desktop.
Bash Commands & tricks
###### ~/.bash_profile ######
alias a='vim ~/.bash_profile && source ~/.bash_profile'
alias gpp='git pull && git push'
# FIND PROCESS
function p(){
ps aux | grep -i $1 | grep -v grep
}
# KILL ALL
function ka(){
cnt=$( p $1 | wc -l)
echo -e "\nSearching for '$1' -- Found" $cnt "Running Processes .. "
p $1
echo -e '\nTerminating' $cnt 'processes .. '
ps aux | grep -i $1 | grep -v grep | awk '{print $2}' | xargs sudo kill -9
echo -e "Done!\n"
echo "Running search again:"
p "$1"
echo -e "\n"
}
# http://bitmote.com/index.php?post/2012/11/19/Using-ANSI-Color-Codes-to-Colorize-Your-Bash-Prompt-on-Linux
# http://misc.flogisoft.com/bash/tip_colors_and_formatting
#
# This file echoes a bunch of color codes to the terminal to demonstrate
# what's available. Each line is the color code of one forground color,
# out of 17 (default + 16 escapes), followed by a test use of that color
# on all nine background colors (default + 8 escapes).
#
function ansi(){
echo -e "\nThis file echoes a bunch of color codes to the terminal to demonstrate \nwhat's available. Each line is the color code of one forground color, \nout of 17 (default + 16 escapes), followed by a test use of that color \non all nine background colors (default + 8 escapes)."
echo -e "\nIf that makes no sense, just concentrate on which numbers to use. \nFont color makes use of 30 to 37. \nBackground color makes use of 40 to 47. \nA 0 (or no value given) for the font color resets it to the default, which depends on the setup. For additional rendering options, 1 sets the font to bright / bold, 4 sets it to underlined, 7 sets it to negative colors."
T='gYw' # The test text
echo -e "\n 40m 41m 42m 43m 44m 45m 46m 47m";
for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' '1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' ' 36m' '1;36m' ' 37m' '1;37m';
do FG=${FGs// /}
echo -en " $FGs \033[$FG $T "
for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
do echo -en "$EINS \033[$FG\033[$BG $T \033[0m\033[$BG \033[0m";
done
echo;
done
echo
}
#
# generates an 8 bit color table (256 colors) for
# reference purposes, using the \033[48;5;${val}m
# ANSI CSI+SGR (see "ANSI Code" on Wikipedia)
#
function 8bit(){
echo -e "\n" "8 bit color table (256 colors) for reference purposes, using the " '\\033[48;5;${val}m' " ANSI CSI+SGR (see "ANSI Code" on Wikipedia)" "\n"
echo -en "\n + "
for i in {0..35}; do
printf "%2b " $i
done
printf "\n\n %3b " 0
for i in {0..15}; do
echo -en "\033[48;5;${i}m \033[m "
done
#for i in 16 52 88 124 160 196 232; do
for i in {0..6}; do
let "i = i*36 +16"
printf "\n\n %3b " $i
for j in {0..35}; do
let "val = i+j"
echo -en "\033[48;5;${val}m \033[m "
done
done
echo -e "\n"
}
##########################################
###### download a sequence of urls: ######
curl -o "ditm_#1.png" "http://babel.hathitrust.org/cgi/imgsrv/image?id=mdp.39015063939071;seq=[1-255]"
-o "ditm_#1.png" <-- rename to this format, #1 indicates the number
[1-255] <-- indicates the numeric sequence
[00-20] <-- leading zeros
##################
###### Find ######
#SEARCH & REPLACE IN MULTIPLE FILES
find . -exec sed -i "s/Anthony Fernando/John Doe/g" {} \;
##################
###### SSH ######
#CREATING A BRIDGE / TUNNEL SETUP
Host bridge
HostName *.*.*.*
IdentityFile ~/.ssh/bridge.pem
User ec2-user
Port 443
Host b-osiris
HostName *.*.*.*
User root
ProxyCommand ssh bridge nc %h %p 2> /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment