Search This Blog


sed and symlinks

A note to be careful when using inplace editing with sed (meaning sed -i). It will replace the symlink with an actual file thus destroying the symlink structure.

For example:
We see a symlink for /etc/sysconfig/selinux pointing to /etc/selinux/config. If we sed -i the /etc/sysconfig/selinux file it will break the symlink to the actual /etc/selinux/config and potentially break some functionality dependent on that symlink. The same may be true with /boot/grub/grub.conf

grub.conf structure
ls -l /etc/grub.conf
lrwxrwxrwx. 1 root root 22 May  7 15:42 /etc/grub.conf -> ../boot/grub/grub.conf

Example of destroying a symlink with selinux:
ls -l /etc/sysconfig/selinux
lrwxrwxrwx. 1 root root 17 May  7 15:40 /etc/sysconfig/selinux -> ../selinux/config

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
ls -l /etc/sysconfig/selinux
-rw-r--r-- 1 root root 457 Nov  5 09:20 /etc/sysconfig/selinux


No comments:

Post a Comment