I am trying to use symbolic links. I did some reading and found the following commands:
Creation -> ln -s {/path/to/file-name} {link-name}
Update -> ln -sfn {/path/to/file-name} {link-name}
Deletion -> rm {link-name}
Creations and deletions work fine. But updates do not work. After performing this command, the symlink becomes invalid.
I have read here and there that it is not possible to update/override a symlink. So there is contradictory information on the net. Who is right? If a symlink can be updated/overridden, how can I achieve this?
Update
Here is my directory structure:
~/scripts/test/
~/scripts/test/remote_loc/
~/scripts/test/remote_loc/site1/
~/scripts/test/remote_loc/site1/stuff1.txt
~/scripts/test/remote_loc/site2/
~/scripts/test/remote_loc/site2/stuff2.txt
~/scripts/test/remote_loc/site2/
~/scripts/test/remote_loc/site3/stuff3.txt
From ~/scripts/test/
, when I perform:
ln -s /remote_loc/site1 test_link
a test_link
is created, and I can ls -l
it, but it seems broken (contrary to what I said above in my question).
How can I perform a multiple directory level link?
Using
-f
withln
will overwrite any link that was already there, so as long as you have the correct permissions, it should work... It's always worked for me. What operating system are you using?Ok, I found where my error is: one should not put the first
/
in path.In other words, the commands in my questions should be:
instead of
considering my case.
First issue:
Quoting you:
The problem With the given directory structure:
and using the command:
Is that it creates a symbolic link in your $PWD, or present working directory, that points to a non-existing file off the /, or root, at /remote_loc/site1
If your PWD is in ~/scripts/ then you should have used this:
ln -s remote_loc/site1 test_link
else you could have used the full absolute path like:
ln -s /home/yourusername/remote_loc/site1 test_link
Second issue:
Quoting you:
To answering your question "Who is right", I am not sure what exactly you read, or how it was understood. But, the following should help clear up:
Updating symbolic links with targets that are not directories.
Example:
But, as you can see, it will give the absolute path if absolute paths are in
ln
's arguments. Giving a full path is necessary when the present working directory is different than the link's parent directory.Relative Paths:
Example:
But, updating a link to a directory will not work if the target is a directory.
Example:
As you can see, despite using absolute path names given in
ln
's argument above without the -r option, the symbolic link is still relative to the link.Update Links to Directories:
Example:
As contrasted with: