Summary of find command

From: Parks Fields (parks@xdiv.lanl.gov)
Date: Mon May 05 1997 - 10:15:03 CDT


Original post:

> Hello world.
>
> I once had a find command that would search every file on the machine for a certain
> pattern.
> I have lost it and failed to recreate it.

Summary:
find . -type f -exec grep -l <pattern_to_be_found> {} \
find / -type d -print | xargs grep GREPPARMS
find {dir_name} -name '*' -exec grep -b -l {string} {}\;
find . -print | xargs egrep $1
find . -type f -print | xargs grep -s string
find / -print | xargs grep hello /dev/null
WARNING: slow slow slow slow slow!
find / -exec grep <pattern> {} /dev/null \; | more

If you only want to search text files, try:
find / -type f -exec grep <pattern> {} /dev/null \; | more
find / -name ?*.txt -print
find <path> -exec grep -l <pattern> {}\;

Thanks to : Sorry if I missed anyone, I don't think I did.
Derek_Schatz@amat.com
jon.anderson@gs.com
bismark@alta.Jpl.Nasa.Gov
mikey@fimad.lanl.gov
sweh@mpn.com
emarch@pinole1.com
clg@csph.psu.edu
ari@arx.com
Mariel Feder <unix.support@central.meralco.com.ph>
brett@gims.com
roy@bluestone.COM

#!/bin/ksh

# Scripts that greps into a the subdirectories recursively.
# Sintaxis: Supergrep [-d directory] [ -c condition] xxxx
# xxx = String to search for
# directorio = Directory to start from (default: . )
# condition = Files to search into (default: *)

if [ $# -lt 1 ]
then
       echo
       echo "USAGE: $0 [-d directory] [ -c condition] xxxx"
       echo "Help: $0 -h"
       echo
       exit 1
fi

while getopts hc:d: bandera
do
     case $bandera in
         h) echo
                echo "======================================================================="
                echo
                echo "USAGE: $0 [-d directory] [ -c condition] xxxx"
                echo " directory = directory to start the search from (default: .)"
                echo " condition = files to search in (default: *)"
                echo " xxxx = string to search for"
                echo
                echo " (metacharacters to restrict the files to search must be preceded with \\)"
                echo
                echo
                echo "example: $0 -h"
                echo
                echo "example: $0 -d /soft/desar/include -c \*.h STRING"
                echo
                echo "example: $0 -c pp\* string1"
                echo
                echo "example: $0 \"string to look for\" "
                echo
                echo
                echo "======================================================================="
                echo
                exit 0;;
         d) directorio=$OPTARG;;
         c) condicion=$OPTARG;;
             ?) echo
                        echo "USAGE: $0 [-d directory] [ -c condition] [-h] xxxx"
                       echo "Help: $0 -h"
                        echo
                exit 2;;
             :) echo
                echo "USAGE: $0 [-d directory] [ -c condition] [-h] xxxx"
                       echo "Help: $0 -h"
                echo
                exit 3
     esac

done

shift `expr $OPTIND-1`

if [ $# -le 0 ]
then
        echo
               echo "USAGE: $0 [-d directory] [ -c condition] [-h] xxxx "
        echo "Help: $0 -h"
        echo exit 4
fi

buscar=$*
if [ -z "$condicion" ]

then
    condicion='*'
fi

if [ -z "$directorio" ]
then
    directorio='.'
fi
echo $1 > /tmp/${USER}_${PPID}
echo
egrep -f /tmp/${USER}_${PPID} `find $directorio -name "$condicion" -type f -print`
\rm /tmp/${USER}_${PPID}
echo
exit 0



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:11:54 CDT