Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an installed application in /home/appuser/app/ In that directory there is a separate directory confs for the config files, which is symlinked to ../app-confs, like so:

lrwxrwxrwx  1 appuser appuser    19 Mar 25 15:22 confs -> ../app-confs/

Looks fine, works fine.

Now I'd like other users to use that application from the same directory (/home/appuser/app/), so the updates can be done in only one place, but with a different configs directory.

So I create a symlink in /home/user-a/ to /home/appuser/app/. And I create a new configs directory confs in /home/user-a/.

When list /home/user-a/, I do see

drwxr-xr-x  8 user-a  user-a   4096 Apr 29 10:57 app
drwxr-xr-x  8 user-a  user-a   4096 Apr 29 10:57 app-confs

and in /home/user-a/app, I see

...
lrwxrwxrwx  1 appuser appuser    19 Mar 25 15:22 confs -> ../app-confs/
...

But when I list /home/user-a/confs/, I see files from /home/appuser/confs/, the original confs and not the relative one.

Is there a way to have a relative symlink with a symlinked directory?

Try this:

mkdir ~/TEST
cd ~/TEST
mkdir global
cd global
mkdir app
mkdir conf
touch conf/global_conf
cd app
ln -s ../conf conf

cd ~/TEST
mkdir user
cd user
ln -s ~/TEST/global/app app
mkdir conf
touch conf/user_conf
cd app
ls -l conf/

You would expect "user_conf" file to be shown, or not?

share|improve this question

2 Answers 2

Q: You would expect "user_conf" file to be shown, or not?

A: Negative!

Symbolic links are like cd - when you enter into a symlinked directory, you are effectively cding into the target directory. Therefore all relative paths (i.e. symbolic links) in that (and any other) directory will be relative to the physical location of the directory where the symlink is located. In other words...

cd ~/TEST/user/app

is effectively

cd ~/TEST/global/app

because of the last line of

cd ~/TEST
mkdir user
cd user
ln -s ~/TEST/global/app app

And here's proof (the -P parameter shows you the physicalcurrent working directory - i.e. resolves symlinks, whereas pwd without any parameters normally shows you the logical current working directory):

pwd -P
/home/rouben/TEST/global/app/conf

pwd
/home/rouben/TEST/user/app/conf

Unfortunately there's no way to eat the cake and have it too! I suggest you exercise caution with symlinks, especially if you're programming... this kind of setup can have unintended consequences!

Try this simpler example:

cd ~
ln -s / root_of_everything
cd root_of_everything
pwd
/home/rouben/root_of_everything
pwd -P
/

The first pwd outputs the "fake" logical path. The second pwd, with the -P outputs the actual physical path. Any symbolic links I wish to create under "root_of_everything" will have to be relative to the physical, not logical path.

share|improve this answer
    
I get it :) What could I do to get the whole thing working the way I want to. So there is 1 global app with a symlink to a config-dir which is relative to the users' dirs? –  ddofborg Apr 29 '13 at 15:24

It seems to me that something went wrong there. Listing /home/user-a/ should show a symlink app and a real directory app-confs. conf should be shown in a listing of /home/user-a/app only. So I recommend you remove everything from /home/user-a/ and show us the commands you used (if it does not work again).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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