Created
February 13, 2012 19:15
-
-
Save sambatyon/1819232 to your computer and use it in GitHub Desktop.
My own bashrc file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if [ -n "$PS1" ]; then | |
| alias ls='ls -h --color' | |
| alias grep='grep --color' | |
| alias egrep='egrep --color' | |
| alias fgrep='fgrep --color' | |
| else | |
| alias ls='ls -h' | |
| fi | |
| alias ll='ls -l --group-directories-first' | |
| alias la='ls -Al' # show hidden files | |
| alias lx='ls -lXB' # sort by extension | |
| alias lk='ls -lSr' # sort by size, biggest last | |
| alias lc='ls -ltcr' # sort by and show change time, most recent last | |
| alias lu='ls -ltur' # sort by and show access time, most recent last | |
| alias lt='ls -ltr' # sort by date, most recent last | |
| alias lm='ls -al | less' # pipe through 'more' | |
| alias lr='ls -lR' # recursive ls | |
| alias tree='tree -Csu' # nice alternative to 'recursive ls' | |
| alias more='less' | |
| #------------------------------------------------------------- | |
| # File & string-related functions: | |
| #------------------------------------------------------------- | |
| # Find a file with a pattern in name: | |
| function ff() { find . -type f -iname '*'$*'*' -ls ; } | |
| # Find a file with pattern $1 in name and Execute $2 on it: | |
| function fe() | |
| { find . -type f -iname '*'${1:-}'*' -exec ${2:-file} {} \; ; } | |
| # Find a pattern in a set of files and highlight them: | |
| # (needs a recent version of egrep) | |
| function fstr() | |
| { | |
| OPTIND=1 | |
| local case="" | |
| local usage="fstr: find string in files. | |
| Usage: fstr [-i] \"pattern\" [\"filename pattern\"] " | |
| while getopts :it opt | |
| do | |
| case "$opt" in | |
| i) case="-i " ;; | |
| *) echo "$usage"; return;; | |
| esac | |
| done | |
| shift $(( $OPTIND - 1 )) | |
| if [ "$#" -lt 1 ]; then | |
| echo "$usage" | |
| return; | |
| fi | |
| find . -type f -name "${2:-*}" -print0 | \ | |
| xargs -0 egrep --color=always -sn ${case} "$1" 2>&- | more | |
| } | |
| function lowercase() # move filenames to lowercase | |
| { | |
| for file ; do | |
| filename=${file##*/} | |
| case "$filename" in | |
| */*) dirname==${file%/*} ;; | |
| *) dirname=.;; | |
| esac | |
| nf=$(echo $filename | tr A-Z a-z) | |
| newname="${dirname}/${nf}" | |
| if [ "$nf" != "$filename" ]; then | |
| mv "$file" "$newname" | |
| echo "lowercase: $file --> $newname" | |
| else | |
| echo "lowercase: $file not changed." | |
| fi | |
| done | |
| } | |
| function swap() # Swap 2 filenames around, if they exist | |
| { #(from Uzi's bashrc). | |
| local TMPFILE=tmp.$$ | |
| [ $# -ne 2 ] && echo "swap: 2 arguments needed" && return 1 | |
| [ ! -e $1 ] && echo "swap: $1 does not exist" && return 1 | |
| [ ! -e $2 ] && echo "swap: $2 does not exist" && return 1 | |
| mv "$1" $TMPFILE | |
| mv "$2" "$1" | |
| mv $TMPFILE "$2" | |
| } | |
| function extract() # Handy Extract Program. | |
| { | |
| if [ -f $1 ] ; then | |
| case $1 in | |
| *.tar.bz2) tar xvjf $1 ;; | |
| *.tar.gz) tar xvzf $1 ;; | |
| *.bz2) bunzip2 $1 ;; | |
| *.rar) unrar x $1 ;; | |
| *.gz) gunzip $1 ;; | |
| *.tar) tar xvf $1 ;; | |
| *.tbz2) tar xvjf $1 ;; | |
| *.tgz) tar xvzf $1 ;; | |
| *.zip) unzip $1 ;; | |
| *.Z) uncompress $1 ;; | |
| *.7z) 7z x $1 ;; | |
| *) echo "'$1' cannot be extracted via >extract<" ;; | |
| esac | |
| else | |
| echo "'$1' is not a valid file" | |
| fi | |
| } | |
| #------------------------------------------------------------- | |
| # Process/system related functions: | |
| #------------------------------------------------------------- | |
| function my_ps() { ps $@ -u $USER -o pid,%cpu,%mem,bsdtime,command ; } | |
| function pp() { my_ps f | awk '!/awk/ && $0~var' var=${1:-".*"} ; } | |
| function killps() # Kill by process name. | |
| { | |
| local pid pname sig="-TERM" # Default signal. | |
| if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then | |
| echo "Usage: killps [-SIGNAL] pattern" | |
| return; | |
| fi | |
| if [ $# = 2 ]; then sig=$1 ; fi | |
| for pid in $(my_ps| awk '!/awk/ && $0~pat { print $1 }' pat=${!#} ) ; do | |
| pname=$(my_ps | awk '$1~var { print $5 }' var=$pid ) | |
| if ask "Kill process $pid <$pname> with signal $sig?" | |
| then kill $sig $pid | |
| fi | |
| done | |
| } | |
| function my_ip() # Get IP adresses. | |
| { | |
| MY_IP=$(/sbin/ifconfig ppp0 | awk '/inet/ { print $2 } ' | \ | |
| sed -e s/addr://) | |
| MY_ISP=$(/sbin/ifconfig ppp0 | awk '/P-t-P/ { print $3 } ' | \ | |
| sed -e s/P-t-P://) | |
| } | |
| function ii() # Get current host related info. | |
| { | |
| echo -e "\nYou are logged on ${RED}$HOST" | |
| echo -e "\nAdditionnal information:$NC " ; uname -a | |
| echo -e "\n${RED}Users logged on:$NC " ; w -h | |
| echo -e "\n${RED}Current date :$NC " ; date | |
| echo -e "\n${RED}Machine stats :$NC " ; uptime | |
| echo -e "\n${RED}Memory stats :$NC " ; free | |
| my_ip 2>&- ; | |
| echo -e "\n${RED}Local IP Address :$NC" ; echo ${MY_IP:-"Not connected"} | |
| echo -e "\n${RED}ISP Address :$NC" ; echo ${MY_ISP:-"Not connected"} | |
| echo -e "\n${RED}Open connections :$NC "; netstat -pan --inet; | |
| echo | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment