[SLL] find insanity

Russell Evans russell-evans at qwest.net
Tue May 31 15:35:41 PDT 2005


On Fri, 27 May 2005 23:59:54 -0700 (PDT)
"Andrew Sweger" <andrew at sweger.net> wrote:

> On Fri, 27 May 2005, Russell Evans wrote:
> 
> > If by "find me directories that contain a sub-directory named
> > ".svn", print the directory name" you what "/home/revans/projects"
> > when /home/revans/projects/.svn is found then 
> > 
> > for i in `find ~/projects -type d -name .svn -prune` ; do 
> >   echo ${i%/*} 
> > done
> > 
> > revans at linux:~> for i in `find ~/projects -type d -name .svn -prune`
> > ; do echo ${i%/*} ; done 
> > /home/revans/projects/bar/baz
> > /home/revans/projects
> > 
> > Is this what you where looking for?    
> 
> Close. I don't want to know about ~/projects/bar/baz because it's
> under a directory that already contains a .svn directory.
> 
> I guess another way to describe my search: find all the top level
> directories that contain a CVS or Subversion tree within them.

Find and grep solution bash script.

Thank you
Russell


#!/bin/sh

HELP="$0 -d [ directory path to search ] -p [ direstory name to search
for ]"

getopt -o :d:p 1> /dev/null
for ARG in $@ ; do
  case "$ARG" in
    -d) shift ; DIRECTORY="$1" ; shift ;;
    -p) shift ; PATTERN="$1" ; shift  ;;
  esac
done

if [ ! $DIRECTORY ] || [ ! $PATTERN ] ; then
  echo "$HELP" 
  exit 0
fi

for dir in `find $DIRECTORY -type d -name "$PATTERN" -prune` ; do 
  DIR=${dir%/*} 
  if [ "$ALL_DIR" ] ; then 
    for TEST_DIR in $ALL_DIR ; do 
      DIR_FOUND=`eval echo $DIR | grep TEST_DIR` 
      TEST_DIR_FOUND=`eval echo $TEST_DIR | grep $DIR`
      if [ ! $DIR_FOUND ] && [ ! $TEST_DIR_FOUND ] ; then
        ALL_DIR="$DIR $ALL_DIR"
        break
      elif  [ $TEST_DIR_FOUND ] ; then
        ALL_DIR="$DIR"
        break
      fi
    done
  else
    ALL_DIR="$DIR"
  fi
done
echo $ALL_DIR 
exit 0 
 




More information about the linux-list mailing list