• 🏠 Home
  • 🧰 Online Generators
  • 📰 Blog
  • 🔎 Search
  • 📧 Contact
  • 📘 Guestbook
  • 🗞️ News
  • 💰 Support
  • ℹ️ Info: The website has been modernized to improve readability and smartphone compatibility. Feel free to report any bugs using the contact form

    RGrep - Recursive Grep


    Presentation

      This script is an update of the command grep. It allows to search in the current directory and subdirectories ..
      Here is the syntax:
        rgrep <string> <filter>
      Example:
        rgrep jerome *
      Will search for "jerome" string in the current directory and subdirectories.

    The script

      ########################################################
      ## Script: rgrep (Recursive Grep)                       #
      ## Version: 1.00 - June 2008                            #
      ## Author: Jerome DESMOULINS (http://www.desmoulins.fr) #
      #########################################################
      ## This script is a recursive grep. Usage is the same   #
      ## than grep Unix command.                              #
      #########################################################
      PN=`basename "$0"` # Program name
      VER=`echo '$Revision: 1 $' | cut -d' ' -f2`
      
      : ${GREP:=egrep}
      FindOpts="-follow -type f"
      GrepOpts=
      
      #Command line usage
      Usage () {
      echo >&2 "$PN - recursive grep, $VER
      usage: $PN [grep_opts | find_opts] SearchString [file | directory] ...
      grep_opts: Options for $GREP (the default is \"$GrepOpts\")
      find_opts: Options for find (the default is \"$FindOpts\")."
      exit 1
      }
      
      #Show Message
      Msg () {
      for i
      do echo "$PN: $i" >&2
      done
      }
      
      #In case of fatal error
      Fatal () { Msg "$@"; exit 1; }
      
      Args=
      while [ $# -gt 0 ]
      do
      case "$1" in
      --) shift; break ;;
      -h) Usage;;
      -?) GrepOpts="${GrepOpts:+$GrepOpts }$1";;
      -??*) Args="${Args:+$Args }$1";;
      *) break ;; # First file name
      esac
      shift
      done
      
      [ -n "$Args" ] && FindOpts="$Args"
      
      [ $# -lt 1 ] && Usage
      Search="$1"; shift
      
      [ $# -lt 1 ] && set -- . # Default search directory
      
      exec find "$@" $FindOpts -print | xargs $GREP $GrepOpts "$Search" /dev/null
      
      

     

    Go back


    (c) 2005-2025 Jérôme DESMOULINS
    Data privacy