sed breaks links


When using the stream editor (sed) with the -i option, it does break links. Like this:

~$ mkdir test
~$ cd test
~/test$ echo Hello > f1
~/test$ ln -s f1 f2
~/test$ ls -l
total 4
-rw-r--r-- 1 tonk tonk 6 May  4 09:28 f1
lrwxrwxrwx 1 tonk tonk 2 May  4 09:28 f2 -> f1
~/test$ sed -i.bck 's/Hello/Bello/' f2
~/test$ ls -l
total 8
-rw-r--r-- 1 tonk tonk 6 May  4 09:28 f1
-rw-r--r-- 1 tonk tonk 6 May  4 09:29 f2
lrwxrwxrwx 1 tonk tonk 2 May  4 09:28 f2.bck -> f1
~/test$ rm f2 f2.bck
~/test$ ln f1 f2
~/test$ ls -l
total 8
-rw-r--r-- 2 tonk tonk 6 May  4 09:28 f1
-rw-r--r-- 2 tonk tonk 6 May  4 09:28 f2
~/test$ sed -i.bck 's/Hello/Bello/' f2
~/test$ ls -l
total 12
-rw-r--r-- 2 tonk tonk 6 May  4 09:28 f1
-rw-r--r-- 1 tonk tonk 6 May  4 09:29 f2
-rw-r--r-- 2 tonk tonk 6 May  4 09:28 f2.bck

According to the sed developers this is a feature and not a bug. Therefore they will add the --follow-symlinks option in version 4.2.

Yep. It’s not a bug.

I have corrected the vigit program, because it uses the -i of sed. The new version can be found here

Old 

See also