[NTLUG:Discuss] Listing file permissions in "chmod format"
Patrick R. Michaud
pmichaud at pobox.com
Fri Apr 16 08:06:16 CDT 2010
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
More information about the Discuss
mailing list