Beta
×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

More useful shell functions

jomama717 (779243) writes | more than 7 years ago

Unix 0

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
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

cancel ×

0 comments

Sorry! There are no comments related to the filter you selected.

Check for New Comments
Slashdot Login

Need an Account?

Forgot your password?

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>