[vox-tech] Shell Scripting Question

Ken Herron vox-tech@lists.lugod.org
Fri, 06 Jun 2003 11:21:47 -0700


--On Friday, June 06, 2003 10:34:36 -0700 Henry House 
<hajhouse@houseag.com> wrote:

> On Fri, Jun 06, 2003 at 10:28:37AM -0700, Richard Crawford wrote:
>>
>> find . -name $1 -print | while read i do
>>   chmod 777 $i
>>   echo "Modified: $i"
>> done
>>
>> Now what I need it to do is to go into only those directories called
>> "messages" and do the same thing to files in those directories.
>
> This seems like a ideal use for xargs. Try:
>
> 	find . -path '*/messages/*' -type f -print0 | xargs -0 chmod 777

That's fine if the host has gnu find and xargs. If it doesn't, and you're 
confident none of the directory names contain white space, then here's a 
more portable method:

	find ... -name messages -type d -print | while read dir
	do
		chmod 777 $dir/*
	done

If these directories contain a huge number of files then the shell may 
balk at expanding that wildcard, in which case you could do:

	find ... -name messages -type d -print | while read dir
	do
		find $dir -type f -exec chmod 777 '{}' ';'
	done

If you're confident that none of the filenames will contain white space, 
the inner find could be replaced with

		find $dir -type f -print | xargs chmod 777

-- 
Kenneth Herron  Kherron@newsguy.com     916-366-7338