Skip to content

saawan/scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

favorite bash functions

#-------------------------------------------------------------

File & strings related functions:

#------------------------------------------------------------- psa () { ps aux | grep $1 }

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 mycase="" local usage="fstr: find string in files. Usage: fstr [-i] "pattern" ["filename pattern"] "

while getopts :it opt
do
    case "$opt" in
       i) mycase="-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>&-

}

function kps() # 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/ && $0pat { print $1 }' pat=${!#} ) do pname=$(my_ps | awk '$1var { print $5 }' var=$pid ) if ask "Kill process $pid <$pname> with signal $sig?" then kill $sig $pid fi done }

function ask() # See 'killps' for example of use. { echo -n "$@" '[y/n] ' ; read ans case "$ans" in y*|Y*) return 0 ;; *) return 1 ;; esac }

function my_ps() { ps $@ -u $USER -o pid,%cpu,%mem,bsdtime,command ; } function pp() { my_ps f | awk '!/awk/ && $0~var' var=${1:-".*"} ; }

alias listen="lsof -P -i -n" alias port='netstat -tulanp'

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published