Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > chown recursively

Reply
Thread Tools

chown recursively

 
 
Tim O'Donovan
Guest
Posts: n/a
 
      06-09-2005
Quick newbie question! Could someone please point out how to use chown()
on directories recursively.

But mostly I'd like to know if there are actually any benefits over using:

system("chown -R $uid:$gid $dir");


Thanks very much!

Tim
 
Reply With Quote
 
 
 
 
Lars Eighner
Guest
Posts: n/a
 
      06-09-2005
In our last episode,
<d8a7r8$6u$(E-Mail Removed)-infra.bt.com>,
the lovely and talented Tim O'Donovan
broadcast on comp.lang.perl.misc:

> Quick newbie question! Could someone please point out how to use chown()
> on directories recursively.


> But mostly I'd like to know if there are actually any benefits over using:


> system("chown -R $uid:$gid $dir");


This is really a unix question, not a perl question. A word of
warning, though: beware of -R and .* -- it will recurse upward
because .. matches .* .

--
Lars Eighner http://www.velocityreviews.com/forums/(E-Mail Removed) http://www.larseighner.com/
War on Terrorism: The Difference Between Us and Them
"We should invade their countries, kill their leaders and
convert them to Christianity." -- Ann Coulter
 
Reply With Quote
 
 
 
 
Tim O'Donovan
Guest
Posts: n/a
 
      06-09-2005
Well my question was actually concerning whether using a Perl function
such as chown() had any benefits over using an equivalent system()
function to achieve the same the results.

Tim


Lars Eighner wrote:
> In our last episode,
> <d8a7r8$6u$(E-Mail Removed)-infra.bt.com>,
> the lovely and talented Tim O'Donovan
> broadcast on comp.lang.perl.misc:
>
>
>>Quick newbie question! Could someone please point out how to use chown()
>>on directories recursively.

>
>
>>But mostly I'd like to know if there are actually any benefits over using:

>
>
>>system("chown -R $uid:$gid $dir");

>
>
> This is really a unix question, not a perl question. A word of
> warning, though: beware of -R and .* -- it will recurse upward
> because .. matches .* .
>

 
Reply With Quote
 
Christopher Nehren
Guest
Posts: n/a
 
      06-09-2005
On 2005-06-09, Tim O'Donovan scribbled these
curious markings:
> Quick newbie question! Could someone please point out how to use chown()
> on directories recursively.


Perhaps a bit of File::Find?

> But mostly I'd like to know if there are actually any benefits over using:
>
> system("chown -R $uid:$gid $dir");


Who says chown exists on the target system? Who says it's in your path?
It's generally a bad idea to "shell out" to external programs when you
can do what you need to do with Perl.

Best Regards,
Christopher Nehren
--
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated". -- Ken Thompson
If you ask the wrong people questions, you get "Joel on Software".
Unix is user friendly. However, it isn't idiot friendly.
 
Reply With Quote
 
Kjetil Skotheim
Guest
Posts: n/a
 
      06-10-2005
On Fri, 10 Jun 2005 01:31:54 +0200, Christopher Nehren
<(E-Mail Removed)> wrote:

> On 2005-06-09, Tim O'Donovan scribbled these
> curious markings:
>> Quick newbie question! Could someone please point out how to use chown()
>> on directories recursively.

>
> Perhaps a bit of File::Find?
>
>> But mostly I'd like to know if there are actually any benefits over
>> using:
>>
>> system("chown -R $uid:$gid $dir");

>
> Who says chown exists on the target system? Who says it's in your path?
> It's generally a bad idea to "shell out" to external programs when you
> can do what you need to do with Perl.



I agree that GENERALLY this is a bad idea. But since chmod in itself
is very unix'ish, isn't it?, I think system should be permitted here.
....or if not permitted, I'd do a chmod to permit it...(uh)




>
> Best Regards,
> Christopher Nehren




--
Kjetil Skotheim
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      06-10-2005
Christopher Nehren <(E-Mail Removed)> wrote:
> On 2005-06-09, Tim O'Donovan scribbled these curious markings:


[snip doing it in native Perl]


>> But mostly I'd like to know if there are actually any benefits over using:
>>
>> system("chown -R $uid:$gid $dir");

>
> Who says chown exists on the target system?



ie. portability between different machines.


> Who says it's in your path?



ie. portability between environments, even on *the same* machine.


> It's generally a bad idea to "shell out" to external programs when you
> can do what you need to do with Perl.



I tell students:

Doing it in native Perl will be safer, faster and more portable
than "shelling out".

Followed by some weasel wording about how that isn't an absolute,
but that it applies in the vast majority of cases.

Shelling out to Mathematica would very likely be preferrable to
getting the same thing done in native Perl for instance.


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Tim O'Donovan
Guest
Posts: n/a
 
      06-10-2005
Thanks for all your informative replies, much appreciated. From now on
I'll be replacing 'shell outs' with the appropriate Perl, where applicable.

So I can assume that using:

open(FIND, "find $path -lname '/home/$username/*' |");
@links = <FIND>;
close(FIND);

to find all the symbolic links in the given path to files in a users
home directory is also not the most resourceful method?!

I have some rethinking to do...


Thanks again,
Tim
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      06-10-2005
Tim O'Donovan <(E-Mail Removed)> wrote:

> From now on
> I'll be replacing 'shell outs' with the appropriate Perl, where applicable.


> open(FIND, "find $path -lname '/home/$username/*' |");



Pipe opens *are* "shelling out".


> to find all the symbolic links in the given path to files in a users
> home directory is also not the most resourceful method?!
>
> I have some rethinking to do...



And some reading:

perldoc File::Find

perldoc -f -X


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      06-10-2005
Tim O'Donovan wrote:
> Quick newbie question! Could someone please point out how to use
> chown() on directories recursively.


Sounds like a job for "use File::Find;".

> But mostly I'd like to know if there are actually any benefits over
> using:
> system("chown -R $uid:$gid $dir");


Of course, there are significant benefits. By using a Perl standard function
you are avoiding to fork an external process and to call an external program
that may or may not exist.
In short you are writing portable code.

jue


 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      06-10-2005
Kjetil Skotheim wrote:
> On Fri, 10 Jun 2005 01:31:54 +0200, Christopher Nehren
>> Who says chown exists on the target system? Who says it's in your
>> path? It's generally a bad idea to "shell out" to external programs
>> when you can do what you need to do with Perl.

>
>
> I agree that GENERALLY this is a bad idea. But since chmod in itself
> is very unix'ish, isn't it?, I think system should be permitted here.
> ...or if not permitted, I'd do a chmod to permit it...(uh)


Where do you find chown on a Windows PC, on a Mac, or a any of the dozen and
dozen OSs that are supported by Perl?

jue


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: chown'ing by script Carsten Haese Python 4 01-06-2010 03:07 PM
os.chown() James Colannino Python 3 11-13-2005 08:33 AM
JNI/Linux/chown GfxGuy Java 6 05-29-2005 11:08 AM
NFS shares (Windows to Unix) chown issues =?Utf-8?B?U3RvcmFnZSBlbmdpbmVlciB3aXRoIHF1ZXN0aW9ucw==?= Microsoft Certification 0 03-17-2005 09:37 PM
[suggestion] File.chown to take user and group *names* Brian Candler Ruby 2 03-02-2005 09:25 AM



Advertisments