Become a fan of Slashdot on Facebook

 



Forgot your password?
typodupeerror
×
Unix

Journal jomama717's Journal: More useful shell functions

Here are some more shell functions that I have found to be extremely useful in a development environment.  Most are made obsolete by using an IDE, but there are always cases where you get stuck in a console writing code.

#
#C/C++ source recursive find: recfind <search_string>
#
function recfind {
    find . -name "*.[ch]*" -print | xargs grep -n "$1";
} 2>/dev/null

#
#Java source recursive find: jrecfind <search_string>
#
function jrecfind {
    find . -name "*.java" -print | xargs egrep -n "$1";
} 2>/dev/null

#
#Generic recursive find: grecfind [<filespec>] <search_string>
#
function grecfind {
    if [ $# -eq 1 ]; then
        findStr=${1};
        fileSpec=*;
    else
        findStr=${2};
        fileSpec=${1};
    fi

    find . -name "${fileSpec}" -print | xargs grep -n ${findStr};
} 2>/dev/null

#
#Find a java class in a deployed application environment: findClass <classname>
#
function findClass {
  echo "Looking in jars..."
  for jarfile in `find . -name "*.jar" -print`; do
    FOUND=(`jar tf $jarfile | grep "$1"`);
    if [ ! -z ${FOUND[0]} ]; then
      echo "Found in $jarfile:";
      for found in ${FOUND[@]}; do
        echo "$found";
      done
    fi
  done
  echo "...done.  Looking on filesystem..."
  find . -name "*$1*.class" -print
  echo "...done."
} 2>/dev/null

This discussion has been archived. No new comments can be posted.

More useful shell functions

Comments Filter:

"When the going gets tough, the tough get empirical." -- Jon Carroll

Working...