ln: create symlink using another symlink
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
Let's suppose I have one file and one directory:
[user@localhost Tests]$ ls -l
total 4
drwxrwxr-x. 2 user user 4096 Oct 8 09:53 dir
-rw-rw-r--. 1 user user 0 Oct 8 09:53 file
I created symlink to file
called symlink1
, and symlink to dir
called dirslink1
:
[user@localhost Tests]$ ls -l
drwxrwxr-x. 2 user user 4096 Oct 8 09:53 dir
lrwxrwxrwx. 1 user user 3 Oct 8 10:03 dirslink1 -> dir
-rw-rw-r--. 5 user user 0 Oct 8 09:53 file
lrwxrwxrwx. 1 user user 4 Oct 8 09:53 symlink1 -> file
Now I created symlinks to symlink1
using ln -s
and ln -sL
:
[user@localhost Tests]$ ln -s symlink1 symlink2
[user@localhost Tests]$ ln -sL symlink1 symlink3
[user@localhost Tests]$ ln -s dirslink1 dirslink2
[user@localhost Tests]$ ln -sL dirslink1 dirslink3
Now, as fat as I understand symlink3
should point to file and dirslink3
should point to dir
. But when I check it, none of the symlink[23] and dirslink [23] points to the original file/directory:
[user@localhost Tests]$ ls -l
drwxrwxr-x. 2 user user 4096 Oct 8 09:53 dir
lrwxrwxrwx. 1 user user 3 Oct 8 10:03 dirslink1 -> dir
lrwxrwxrwx. 1 user user 9 Oct 8 10:03 dirslink2 -> dirslink1
lrwxrwxrwx. 1 user user 9 Oct 8 10:03 dirslink3 -> dirslink1
-rw-rw-r--. 5 user user 0 Oct 8 09:53 file
lrwxrwxrwx. 1 user user 4 Oct 8 09:53 symlink1 -> file
lrwxrwxrwx. 1 user user 8 Oct 8 09:54 symlink2 -> symlink1
lrwxrwxrwx. 1 user user 8 Oct 8 09:54 symlink3 -> symlink1
The question is: Is it possible/How to create symlink to original file using another symlink?
bash ln
add a comment |Â
up vote
1
down vote
favorite
Let's suppose I have one file and one directory:
[user@localhost Tests]$ ls -l
total 4
drwxrwxr-x. 2 user user 4096 Oct 8 09:53 dir
-rw-rw-r--. 1 user user 0 Oct 8 09:53 file
I created symlink to file
called symlink1
, and symlink to dir
called dirslink1
:
[user@localhost Tests]$ ls -l
drwxrwxr-x. 2 user user 4096 Oct 8 09:53 dir
lrwxrwxrwx. 1 user user 3 Oct 8 10:03 dirslink1 -> dir
-rw-rw-r--. 5 user user 0 Oct 8 09:53 file
lrwxrwxrwx. 1 user user 4 Oct 8 09:53 symlink1 -> file
Now I created symlinks to symlink1
using ln -s
and ln -sL
:
[user@localhost Tests]$ ln -s symlink1 symlink2
[user@localhost Tests]$ ln -sL symlink1 symlink3
[user@localhost Tests]$ ln -s dirslink1 dirslink2
[user@localhost Tests]$ ln -sL dirslink1 dirslink3
Now, as fat as I understand symlink3
should point to file and dirslink3
should point to dir
. But when I check it, none of the symlink[23] and dirslink [23] points to the original file/directory:
[user@localhost Tests]$ ls -l
drwxrwxr-x. 2 user user 4096 Oct 8 09:53 dir
lrwxrwxrwx. 1 user user 3 Oct 8 10:03 dirslink1 -> dir
lrwxrwxrwx. 1 user user 9 Oct 8 10:03 dirslink2 -> dirslink1
lrwxrwxrwx. 1 user user 9 Oct 8 10:03 dirslink3 -> dirslink1
-rw-rw-r--. 5 user user 0 Oct 8 09:53 file
lrwxrwxrwx. 1 user user 4 Oct 8 09:53 symlink1 -> file
lrwxrwxrwx. 1 user user 8 Oct 8 09:54 symlink2 -> symlink1
lrwxrwxrwx. 1 user user 8 Oct 8 09:54 symlink3 -> symlink1
The question is: Is it possible/How to create symlink to original file using another symlink?
bash ln
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Let's suppose I have one file and one directory:
[user@localhost Tests]$ ls -l
total 4
drwxrwxr-x. 2 user user 4096 Oct 8 09:53 dir
-rw-rw-r--. 1 user user 0 Oct 8 09:53 file
I created symlink to file
called symlink1
, and symlink to dir
called dirslink1
:
[user@localhost Tests]$ ls -l
drwxrwxr-x. 2 user user 4096 Oct 8 09:53 dir
lrwxrwxrwx. 1 user user 3 Oct 8 10:03 dirslink1 -> dir
-rw-rw-r--. 5 user user 0 Oct 8 09:53 file
lrwxrwxrwx. 1 user user 4 Oct 8 09:53 symlink1 -> file
Now I created symlinks to symlink1
using ln -s
and ln -sL
:
[user@localhost Tests]$ ln -s symlink1 symlink2
[user@localhost Tests]$ ln -sL symlink1 symlink3
[user@localhost Tests]$ ln -s dirslink1 dirslink2
[user@localhost Tests]$ ln -sL dirslink1 dirslink3
Now, as fat as I understand symlink3
should point to file and dirslink3
should point to dir
. But when I check it, none of the symlink[23] and dirslink [23] points to the original file/directory:
[user@localhost Tests]$ ls -l
drwxrwxr-x. 2 user user 4096 Oct 8 09:53 dir
lrwxrwxrwx. 1 user user 3 Oct 8 10:03 dirslink1 -> dir
lrwxrwxrwx. 1 user user 9 Oct 8 10:03 dirslink2 -> dirslink1
lrwxrwxrwx. 1 user user 9 Oct 8 10:03 dirslink3 -> dirslink1
-rw-rw-r--. 5 user user 0 Oct 8 09:53 file
lrwxrwxrwx. 1 user user 4 Oct 8 09:53 symlink1 -> file
lrwxrwxrwx. 1 user user 8 Oct 8 09:54 symlink2 -> symlink1
lrwxrwxrwx. 1 user user 8 Oct 8 09:54 symlink3 -> symlink1
The question is: Is it possible/How to create symlink to original file using another symlink?
bash ln
Let's suppose I have one file and one directory:
[user@localhost Tests]$ ls -l
total 4
drwxrwxr-x. 2 user user 4096 Oct 8 09:53 dir
-rw-rw-r--. 1 user user 0 Oct 8 09:53 file
I created symlink to file
called symlink1
, and symlink to dir
called dirslink1
:
[user@localhost Tests]$ ls -l
drwxrwxr-x. 2 user user 4096 Oct 8 09:53 dir
lrwxrwxrwx. 1 user user 3 Oct 8 10:03 dirslink1 -> dir
-rw-rw-r--. 5 user user 0 Oct 8 09:53 file
lrwxrwxrwx. 1 user user 4 Oct 8 09:53 symlink1 -> file
Now I created symlinks to symlink1
using ln -s
and ln -sL
:
[user@localhost Tests]$ ln -s symlink1 symlink2
[user@localhost Tests]$ ln -sL symlink1 symlink3
[user@localhost Tests]$ ln -s dirslink1 dirslink2
[user@localhost Tests]$ ln -sL dirslink1 dirslink3
Now, as fat as I understand symlink3
should point to file and dirslink3
should point to dir
. But when I check it, none of the symlink[23] and dirslink [23] points to the original file/directory:
[user@localhost Tests]$ ls -l
drwxrwxr-x. 2 user user 4096 Oct 8 09:53 dir
lrwxrwxrwx. 1 user user 3 Oct 8 10:03 dirslink1 -> dir
lrwxrwxrwx. 1 user user 9 Oct 8 10:03 dirslink2 -> dirslink1
lrwxrwxrwx. 1 user user 9 Oct 8 10:03 dirslink3 -> dirslink1
-rw-rw-r--. 5 user user 0 Oct 8 09:53 file
lrwxrwxrwx. 1 user user 4 Oct 8 09:53 symlink1 -> file
lrwxrwxrwx. 1 user user 8 Oct 8 09:54 symlink2 -> symlink1
lrwxrwxrwx. 1 user user 8 Oct 8 09:54 symlink3 -> symlink1
The question is: Is it possible/How to create symlink to original file using another symlink?
bash ln
bash ln
asked 45 mins ago
mrc02_kr
759319
759319
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
-L
only works with hard links; as specified in POSIX:
If the -s option is specified, the -L and -P options shall be silently ignored.
If you have readlink
you can use that:
ln -s -- "$(readlink symlink1)" symlink4
If your readlink
supports the -f
option, you can use that to fully canonicalise the target (i.e. resolve all symlinks in the target’s path, if the target symlink includes other symlinks).
Great, this is actually what I'm looking for
– mrc02_kr
27 mins ago
Thanks @Stéphane, one day it will sink in :-/.
– Stephen Kitt
14 mins ago
add a comment |Â
up vote
2
down vote
You can use cp -P
to make a copy of a symlink:
cp -P symlink2 symlink3
Beware that if the target of the symlink is relative, the above would probably result in a broken link if the copy is not in the same directory as the original.
With zsh
,
ln -s -- symlink2(:P) symlink3
Would create symlink3
as a symlink to the full canonical (symlink-free) path symlink2
, like ln -s -- "$(readlink -f symlink2)" symlink3
but more reliable in that it would still work correctly if that path ended in newline characters.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
-L
only works with hard links; as specified in POSIX:
If the -s option is specified, the -L and -P options shall be silently ignored.
If you have readlink
you can use that:
ln -s -- "$(readlink symlink1)" symlink4
If your readlink
supports the -f
option, you can use that to fully canonicalise the target (i.e. resolve all symlinks in the target’s path, if the target symlink includes other symlinks).
Great, this is actually what I'm looking for
– mrc02_kr
27 mins ago
Thanks @Stéphane, one day it will sink in :-/.
– Stephen Kitt
14 mins ago
add a comment |Â
up vote
2
down vote
accepted
-L
only works with hard links; as specified in POSIX:
If the -s option is specified, the -L and -P options shall be silently ignored.
If you have readlink
you can use that:
ln -s -- "$(readlink symlink1)" symlink4
If your readlink
supports the -f
option, you can use that to fully canonicalise the target (i.e. resolve all symlinks in the target’s path, if the target symlink includes other symlinks).
Great, this is actually what I'm looking for
– mrc02_kr
27 mins ago
Thanks @Stéphane, one day it will sink in :-/.
– Stephen Kitt
14 mins ago
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
-L
only works with hard links; as specified in POSIX:
If the -s option is specified, the -L and -P options shall be silently ignored.
If you have readlink
you can use that:
ln -s -- "$(readlink symlink1)" symlink4
If your readlink
supports the -f
option, you can use that to fully canonicalise the target (i.e. resolve all symlinks in the target’s path, if the target symlink includes other symlinks).
-L
only works with hard links; as specified in POSIX:
If the -s option is specified, the -L and -P options shall be silently ignored.
If you have readlink
you can use that:
ln -s -- "$(readlink symlink1)" symlink4
If your readlink
supports the -f
option, you can use that to fully canonicalise the target (i.e. resolve all symlinks in the target’s path, if the target symlink includes other symlinks).
edited 25 mins ago


Stéphane Chazelas
287k53531868
287k53531868
answered 35 mins ago
Stephen Kitt
149k23331397
149k23331397
Great, this is actually what I'm looking for
– mrc02_kr
27 mins ago
Thanks @Stéphane, one day it will sink in :-/.
– Stephen Kitt
14 mins ago
add a comment |Â
Great, this is actually what I'm looking for
– mrc02_kr
27 mins ago
Thanks @Stéphane, one day it will sink in :-/.
– Stephen Kitt
14 mins ago
Great, this is actually what I'm looking for
– mrc02_kr
27 mins ago
Great, this is actually what I'm looking for
– mrc02_kr
27 mins ago
Thanks @Stéphane, one day it will sink in :-/.
– Stephen Kitt
14 mins ago
Thanks @Stéphane, one day it will sink in :-/.
– Stephen Kitt
14 mins ago
add a comment |Â
up vote
2
down vote
You can use cp -P
to make a copy of a symlink:
cp -P symlink2 symlink3
Beware that if the target of the symlink is relative, the above would probably result in a broken link if the copy is not in the same directory as the original.
With zsh
,
ln -s -- symlink2(:P) symlink3
Would create symlink3
as a symlink to the full canonical (symlink-free) path symlink2
, like ln -s -- "$(readlink -f symlink2)" symlink3
but more reliable in that it would still work correctly if that path ended in newline characters.
add a comment |Â
up vote
2
down vote
You can use cp -P
to make a copy of a symlink:
cp -P symlink2 symlink3
Beware that if the target of the symlink is relative, the above would probably result in a broken link if the copy is not in the same directory as the original.
With zsh
,
ln -s -- symlink2(:P) symlink3
Would create symlink3
as a symlink to the full canonical (symlink-free) path symlink2
, like ln -s -- "$(readlink -f symlink2)" symlink3
but more reliable in that it would still work correctly if that path ended in newline characters.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
You can use cp -P
to make a copy of a symlink:
cp -P symlink2 symlink3
Beware that if the target of the symlink is relative, the above would probably result in a broken link if the copy is not in the same directory as the original.
With zsh
,
ln -s -- symlink2(:P) symlink3
Would create symlink3
as a symlink to the full canonical (symlink-free) path symlink2
, like ln -s -- "$(readlink -f symlink2)" symlink3
but more reliable in that it would still work correctly if that path ended in newline characters.
You can use cp -P
to make a copy of a symlink:
cp -P symlink2 symlink3
Beware that if the target of the symlink is relative, the above would probably result in a broken link if the copy is not in the same directory as the original.
With zsh
,
ln -s -- symlink2(:P) symlink3
Would create symlink3
as a symlink to the full canonical (symlink-free) path symlink2
, like ln -s -- "$(readlink -f symlink2)" symlink3
but more reliable in that it would still work correctly if that path ended in newline characters.
edited 21 mins ago
answered 30 mins ago


Stéphane Chazelas
287k53531868
287k53531868
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f473928%2fln-create-symlink-using-another-symlink%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password