[NTLUG:Discuss] Listing file permissions in "chmod format"
Leroy Tennison
leroy_tennison at prodigy.net
Fri Apr 16 00:44:34 CDT 2010
Robert Citek wrote:
> Have a look at stat. For example:
>
> $ touch foo
> $ stat -c %a foo
> 644
>
> Your script would then look something like this:
>
> state=$(stat -c %a {file})
> chmod a+w {file}
> cp -p {file} {file}.{date}
> sed -i (script) {file}
> chmod $state {file}
>
> Good luck and let us know how things go.
>
> Regards,
> - Robert
>
> On Thu, Apr 15, 2010 at 11:37 PM, Leroy Tennison
> <leroy_tennison at prodigy.net> 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}
>>
>> "man ls" didn't provide any other program in the "See also" category.
>> Searching the web produces all kinds of references to ls and a reference to
>> a Perl script. I really don't want to use Perl because, again, I don't know
>> much about the hosts the script will run on and don't want to assume that
>> Perl is universally available.
>>
>> Any ideas or solutions would be appreciated.
>>
>> _______________________________________________
>> http://www.ntlug.org/mailman/listinfo/discuss
>>
>>
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
>
>
Thank you, tested and that works.
More information about the Discuss
mailing list