9fans archive / 1997 / 09 / 11 /    prev next

From: Ed Wishart ed@cs....
Subject: [9fans] Questions
Date: Tue, 2 Sep 1997 10:22:08 -0700

Here are a couple of rc scripts that I wrote some years back to look
for files in the file system hierarchy .  They run slow but
do maintain the limited view of the file system one gets ignoring binds.
e.g. started in home directory, they will search rc/bin but not get lost
in /bin even though rc/bin is bound to /bin.

---------------------------------------

#!/bin/rc
#recursive decent of file system, with local directory stack and
#internal execution of this file.  ed wishart, nov '93 
if(~ $#* 0 1) {
	echo 'Usage: find directory file1 file2 ...'
	exit 1
}
dir = $1
shift
if(! test -d $dir) {
	echo 'First argumant must be a directory'
	exit 1
}
cd $dir
for(file in `{ls}) {
	if(~ $file $*) {
		echo  `{pwd}^/^$file
	}
	if(test -d $file) {
		dstack = `{echo `{pwd} $dstack}
#		echo 'dstack =' $dstack
		. find $file $*
		cd $dstack(1)
		dstack = $dstack(`{seq 2 $#dstack})
	}
}


--------------------------------------------------------

#!/bin/rc
#recursive traversal of file tree with environments managed by
#rc o its execution stack.  ed wishart nov '93 
if(~ $#* 0 1) {
	echo 'Usage: find directory file1 file2 ...'
	exit 1
}
dir = $1
shift
if(! test -d $dir) {
	echo 'First argumant must be a directory'
	exit 1
}
cd $dir
for(file in `{ls -p }) {
	if(~ $file $*) {
		echo  `{pwd}^/^$file
	}
	if(test -d $file) {
		find2 $file $*
	}
}

Note, the above assumes file in named find2

ed wishart