Bluehost.com Web Hosting $6.95

Need a Quick Shell Script

This is a discussion on Need a Quick Shell Script within the Linux General forums, part of the Linux Forums category; On Fri, 11 Mar 2005 at 23:19 GMT, Simon wrote: > on 8 Mar 2005 21:17:26 GMT, &...


Go Back   Usenet Forums > Linux Forums > Linux General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 03-12-2005
Chris F.A. Johnson
 
Posts: n/a
Default Re: Need a Quick Shell Script

On Fri, 11 Mar 2005 at 23:19 GMT, Simon wrote:
> on 8 Mar 2005 21:17:26 GMT, "Chris F.A. Johnson" <cfajohnson@gmail.com> wrote
> this wisdom:
>
>>On Tue, 08 Mar 2005 at 20:57 GMT, Robert M. Riches Jr. wrote:
>>> On 2005-03-08, David P. Donahue <ddonahue@ccs.neu.edu> wrote:
>>>> I'm sure this is very easy, and I'm probably just on crack for not
>>>> knowing how to do it at the moment (we've all had those days), but can
>>>> anyone give me a quick command or script that will recursively
>>>> chown/chmod all files with a given pattern in the name (the file
>>>> extension, in this case, so ideally it would match only the end of the
>>>> name) in a given directory tree? "/bin/chown -R user:group
>>>> /path/to/tree/*.ext" doesn't seem to successfully recurse to .ext files
>>>> beneath the given tree root. Thanks.
>>>
>>> In the above command, the shell expands the last argument
>>> (the one with the file path and wildcard) to a list of all
>>> the files in the specified path with the specified
>>> extension. Then, the chown command with the -R option takes
>>> each one and changes the ownership of that file and anything
>>> below it, if any of your *.ext files were actually
>>> directories.
>>>
>>> What it sounds like you want to do would be accomplished by
>>> something of the form
>>>
>>> chown user:group `find /path/to/tree -name '*.ext'`

>>
>> This will fail if there are spaces in any file names and may fail
>> if there are special characters (e.g., *, ?).

>
> would this do?
>
> find /path/to/tree -name "*.ext" -exec chmod user:group {} \;


Yes, but it calls chmod for every file; if you use xargs, as many
files will be handed to each instance of chmod as your system can
handle:

find /path/to/tree -name "*.ext" -print0 | xargs -0 chmod user:group

Using -print0 and -0 ensure that all filenames will be properly
handled.


--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
================================================== =================
My code (if any) in this post is copyright 2005, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
Reply With Quote
  #12 (permalink)  
Old 03-12-2005
John Hasler
 
Posts: n/a
Default Re: Need a Quick Shell Script

Simon writes:
> Ah, my answer - but why is the first one faster?


The second execs chown once per file. The first chowns them in bunches.
--
John Hasler
john@dhh.gt.org
Dancing Horse Hill
Elmwood, WI USA
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:36 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0