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, &...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |