Why is sed destroying my symlinks?
Issue
- Running
sed -i(in-place edit) against a symlink should edit the file the symlink points to. Instead, it destroys the symlink and creates a new file with the edited contents where the symlink was. The original file that was linked to remains unchanged.
# ln -s dest link
# ls -l
total 0
-rw-r--r-- 1 root root 0 Jul 10 13:49 dest
lrwxrwxrwx 1 root root 4 Jul 10 13:49 link -> dest
# sed -i 's/foo/bar/g' link
# ls -l
total 0
-rw-r--r-- 1 root root 0 Jul 10 13:49 dest
-rw-r--r-- 1 root root 0 Jul 10 13:49 link
Environment
- Red Hat Enterprise Linux 5
- Red Hat Enterprise Linux 6
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.