Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.utils.bug > #2183

Re: 'sed -i' fails if the file has sufficient perms but not its directory

From Bob Proulx <bob@proulx.com>
Newsgroups gnu.utils.bug
Subject Re: 'sed -i' fails if the file has sufficient perms but not its directory
Date 2015-07-03 19:51 -0600
Message-ID <mailman.6268.1435974674.904.bug-gnu-utils@gnu.org> (permalink)
References <5596D2E9.2000007@gmx.de>

Show all headers | View raw


Toralf Förster wrote:
> I tried this, which won't work :
> 
> tinderbox@tor-relay ~ $ 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
> 
> tinderbox@tor-relay ~ $ 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

Back to gnu.utils.bug | Next | Find similar


Thread

Re: 'sed -i' fails if the file has sufficient perms but not its directory Bob Proulx <bob@proulx.com> - 2015-07-03 19:51 -0600

csiph-web