2

I have a number of files in /etc/rc3.d/ directory which all are symbolic links and point to files in /etc/init.d/ directory using ../init.d/ designation. For example file S18rsyslog in /etc/rc3.d/ directory is a symbolic link to file /etc/init.d/rsyslog, but according to ls -l, /etc/rc3.d/S18rsyslog does not point to /etc/init.d/rsyslog but ../init.d/rsyslog instead:

# ls -l /etc/rc3.d/S18rsyslog
lrwxrwxrwx 1 root root 17 30. jun 15:05 /etc/rc3.d/S18rsyslog -> ../init.d/rsyslog
# 

What is the advantage to keep symbolic links relative to directory? Because this allows one to move the direcoty itself without breaking the symbolic links? In addition, is it possible to create a symbolic link with ..(parent directory) in the path without being in the directory? ln -sv '/etc/init.d/rsyslog' '/etc/rc3.d/../init.d/rsyslog' obviously does not work as symlink is created into /etc/init.d/ directory while I would like to have symlink named ../init.d/rsyslog in the /etc/rc3.d/ directory.

3

What is the advantage to keep symbolic links relative to directory? Because this allows one to move the direcoty itself without breaking the symbolic links?

Exactly.

In addition, is it possible to create a symbolic link with .. (parent directory) in the path without being in the directory? ln -sv '/etc/init.d/rsyslog' '/etc/rc3.d/../init.d/rsyslog' obviously does not work as symlink is created into /etc/init.d/ directory while I would like to have symlink named ../init.d/rsyslog in the /etc/rc3.d/ directory.

So you mean to express ln -s ../init.d/rsyslog /etc/rc3.d

In order to not slip on symlinks it is best to keep in mind that ln has the semantic of ln TARGET LINK and that a symlink is in essence a file at LINK that contains TARGET; if TARGET is a relative pathname, then TARGET substitutes the symlink relative to its containing directory. Thus, ln -s X/Y A/B/ becomes A/B/X/Y.

  • Thanks! I think I forgot how to compute when I wrote this ln -sv '/etc/init.d/rsyslog' '/etc/rc3.d/../init.d/rsyslog' :) – Martin Jul 31 '14 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.