With backup:
If the
-i
is followed by a
suffix, a corresponding backup is created before the file is edited.
The following example Creates the backup file /path/to/file.bak
and modifies /path/to/file
.
sed -i.bak s/PAT/REPL/ /path/to/file
sed: couldn't open temporary file /path/to/unwritable/directory/sedXXXXXX: Permission denied
If using sed -i
to edit a file in place, the user must have write permissions in the directory where the edit file is located because sed
tries to create a temporary file with the modified content in this directory before overwriting the edited file with the temporary file.
If the user does not have write privileges on this directory, the error message sed: couldn't open temporary file /path/to/unwritable/directory/sedXXXXXX: Permission denied is thrown.