[NTLUG:Discuss] Listing file permissions in "chmod format"

Leroy Tennison leroy_tennison at prodigy.net
Fri Apr 16 23:49:51 CDT 2010


Patrick R. Michaud wrote:
> On Thu, Apr 15, 2010 at 10:37:45PM -0500, Leroy Tennison wrote:
>   
>> The issue I'm facing is that I'm writing a script which will be used
>> by others on hosts where I have no access or knowledge of the
>> specifics.  I know I need to modify a file which I have seen is
>> read-only (444) in one case.  What I want to do is:
>>
>> "capture" the current permissions in a form usable by chmod
>> chmod a+w {file}
>> cat {file} | sed (script) > {newfile}
>> mv {file} {file}.{date}
>> mv {newfile} {file}
>> chmod (saved permissions) {file}
>>     
>
> Under Linux, the chmod(1) command has a --reference= option that lets
> you set files' permissions to the same mode as an existing file.
> Thus you can do:
>
>     cat {file} | sed {script} > {newfile}
>     chmod {newfile} --reference={file}
>     mv {file} {file}.{date}
>     mv {newfile} {file}
>
> and {newfile} will have the same permissions as {file}.
>
> I don't know if other Unix's have this form of chmod(1) available,
> though.
>
> Pm
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
>
>   
Thanks, that's good to know, always better to have a couple of ways to 
do it.  And, unfortunately, other UNIX's (such as SunOS 5.9) do NOT have 
this switch for chmod...



More information about the Discuss mailing list