Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 3
    Basically true for reason and solution, but not exact: perl -i (without any extension following -i) will rename the original file to some temporary file, process it into the new file with the original name and then unlink the the (original) temporary file. So no actual "backup" file. Commented Jun 21, 2024 at 22:39
  • But it tries to create the "some temporary file" in /etc, see above explanation. Commented Jun 21, 2024 at 22:59
  • 4
    Like I said, your answer and reasoning is basically right (write permission to /etc is needed since new files are created there), with the only exception that this is not a backup file but a temporary file which gets deleted afterwards. Commented Jun 21, 2024 at 23:04
  • 3
    Or to save one step sed [...] /etc/myfile > "$HOME"/myfile; cp "$HOME"/myfile /etc/myfile (with added quoting) Commented Jun 22, 2024 at 2:30
  • 4
    would suggest instead sed [...] /etc/myfile > "$HOME"/myfile && cp "$HOME"/myfile /etc/myfile so that it only replaces original if there are no errors. Commented Jun 22, 2024 at 10:45