sed --in-place caveats

How the "in-place" option works

The in-place option describes what appears to be performed. It actually creates a temporary file named 'sedXXXXXX' where XXXXXX is a string of random characters. As processing progresses output is written to the tempporary file. Upon completion the original file is unlinked(removed) and the temporary file is renamed to the original name.

--inplace (-i) modifies read-only files

The permissions of a file define what operations are permitted on the contents of that file. The permissions of a directory define what operations are permitted on the list of files. Renaming or deleting a file operates on the directory. The use of --in-place on a file without write permission will result in the modification date being updated and may change contents of the file. `sed d --in-place' will delete the contents of a read-only file Attempts to operate on a writeable file in a non-writable directory will produce the error message: sed: couldn't open temporary file seduwDhDf: Permission denied and exit with a code of 4.

Effects on attributes

The flags archived, opaque, nodump, sappend, uappend, simmutable, uimmutable and hidden are lost.

The timestamps on the output file will be now and ACL and eXended attributes are lost.

Effect on links

A file with hard links is seperated and only the file named in the command is changed. For example:
        ls -log 0*
        -rw-r--r--  2 11 Jun  5 12:46 0
        -rw-r--r--  2 11 Jun  5 12:46 0x
        sed --in-place "s/./x/" 0
        ls -log 0*
        -rw-r--r--  1 11 Jun  5 12:47 0
        -rw-r--r--  1 12 Jun  5 12:46 0x
When a symbolic link is operated on it is removed and the temporary file is renamed using the name of the symbolic link. For example:
    ls -log 0*
    -rw-r--r--  1 12 Jun  5 12:57 0
    lrwxr-xr-x  1  1 Jun  5 12:57 0s@ -> 0
    sed --in-place "s/./xx/" 0s
    ls -log 0*
    -rw-r--r--  1 12 Jun  5 12:57 0
    -rw-r--r--  1 13 Jun  5 12:59 0s
    -rw-r--r--  1 12 Jun  5 12:57 0

File space

There must be sufficient space for both the original file and the temporary file.