l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2003 Jun 09 10:30

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] Shell Scripting Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] Shell Scripting Question

--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"

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
chmod 777 $dir/*

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
find $dir -type f -exec chmod 777 '{}' ';'

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
vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.