Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
DEAL: For $25 - Add A Second Phone Number To Your Smartphone for life! Use promo code SLASHDOT25. Also, Slashdot's Facebook page has a chat bot now. Message it for stories and more. Check out the new SourceForge HTML5 internet speed test! ×
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:

"In matters of principle, stand like a rock; in matters of taste, swim with the current." -- Thomas Jefferson

Working...