Cloning File Protection?

Tom Christiansen tchrist at convex.COM
Sun Oct 7 08:10:49 AEST 1990


In article <277 at talarian.UUCP> scott at talarian.UUCP (Scott Weitzenkamp) writes:
>  I am trying to write a shell script (either in sh or csh on SunOS 4.0.3)
>that can clone the file protection from one file to another.  I'd like
>to do something like this:
>
>    chmod `get_protection old_file_name` new_file_name

[Solution in C deleted.]

>   I have a feeling this is probably easy to do in Perl, but I not
> really interested in a Perl solution because I cannot guarantee that
> our customers will have Perl (I suppose I could put Perl on our
> product tape, though).  

You're right -- it *is* easy in perl.  Error checking aside, this should
do the trick:

    perl -e 'chmod(((stat(shift))[2] & 0777), @ARGV)' f0 f1 f2 f3 ...

This copies f0's perms to the rest of the list, although it doesn't
propagate set[ug]id or sticky bits -- use 07777 for that behavior.  

How many times will you need to cook up another solution in C because your
customers don't have perl?  I know that this is just one little thing, but
after running into dozens of such little things, I realized I was making
my own life unnecessarily difficult because of that very line of thinking,
so I got perl added to my company's standard utilities tape.  I suggest
you try to do the same.

Just out of curiosity, what other companies supply perl?

--tom
--
 "UNIX was never designed to keep people from doing stupid things, because 
  that policy would also keep them from doing clever things." [Doug Gwyn]



More information about the Comp.unix.questions mailing list