[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 'sed -i' fails if the file has sufficient perms but not its director
From: |
Bob Proulx |
Subject: |
Re: 'sed -i' fails if the file has sufficient perms but not its directory |
Date: |
Fri, 3 Jul 2015 19:51:06 -0600 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
Toralf Förster wrote:
> I tried this, which won't work :
>
> address@hidden ~ $ sed -i -e 's/j1/j2/g' perl-5.22/etc/portage/make.conf
> sed: couldn't open temporary file perl-5.22/etc/portage/sedw9SFZf: Permission
> denied
Correct. If you want to use -i you will need write permission to the
directory. This is the same as other tools such as perl -i and awk -i too.
> whereas I'm allowed to edit that file as the user tinderbox
>
> address@hidden ~ $ vi perl-5.22/etc/portage/make.conf
The behavior depends upon the vi implementation. Some read it into
memory, some into spill files in /tmp, some into .swp files in the
same directory.
> /me wonders if sed relies on having a temp copy of that file in the same dir
> or not.
The documentation for sed says this:
'-i[SUFFIX]'
'--in-place[=SUFFIX]'
This option specifies that files are to be edited in-place. GNU
'sed' does this by creating a temporary file and sending output to
this file rather than to the standard output.(1).
...
When the end of the file is reached, the temporary file is renamed
to the output file's original name. The extension, if supplied, is
used to modify the name of the old file before renaming the
temporary file, thereby making a backup copy(2)).
Bob