0

Let's say that I am currently in /a/b/c/d/e/, and I want to make symbolic link with a file f.txt in that directory. If I do ln -s f.txt /etc/, the file /etc/f.txt will not point to the file, because it just points f.txt, not /a/b/c/d/e/f.txt. I have tried ln -s ./f.txt /etc/, but that created a link literally to ./f.txt.

So, other than typing the full path myself, like /a/b/c/d/e/f.txt, is there any shortcut to tell ln that I want to use the absolute path of the file in the current directory?

0

3 Answers 3

1

One possible way is to use command like:

ln -s "$(pwd)/f.txt" /etc/

The command pwd will add the current path to the filename.

0

ln command has the option --relative however I'm not sure if this a GNUism since I did not found anything related to --relative in POSIX manual (man 1p ln).

From man ln (option 1) or ln --help:

-r, --relative

with -s, create links relative to link location

So if you have Linux (with gnu software) you can use:

ln -s --relative f.txt /etc/
-2

Another solution:

ln -s ${PWD}/f.txt /etc/
2
  • @Kusalananda I like curly braces around variables.
    – RonJohn
    Commented Apr 19, 2023 at 4:49
  • 4
    Whatever you like, you should be quoting it
    – muru
    Commented Apr 19, 2023 at 4:51

Not the answer you're looking for? Browse other questions tagged .