How to prevent sed -i command overwriting my symlinks on Linux or Unix

‮//:sptth‬www.lautturi.com
How to prevent sed -i command overwriting my symlinks on Linux or Unix

The sed -i command (which stands for "in-place") is used to edit a file by replacing specified text patterns with new text. By default, sed -i will overwrite the original file, which can cause problems if the file is a symbolic link (symlink).

To prevent sed -i from overwriting symlinks, you can use the --follow-symlinks option. This option tells sed to follow the symlink and edit the file that the symlink points to, rather than overwriting the symlink itself.

For example, to edit a file /path/to/file and follow any symlinks, you can use the following command:

sed --follow-symlinks -i 's/pattern/replacement/g' /path/to/file

This will edit the file that the symlink points to, rather than overwriting the symlink itself.

Note: The --follow-symlinks option is not available on all versions of sed. If the option is not recognized by your version of sed, you can try using the -L option instead.

For more information about using the sed command and the --follow-symlinks option, you can refer to the sed man page or search online for tutorials and examples.

Created Time:2017-10-28 21:39:06  Author:lautturi