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?

Damn Vegetables
  • 1,187
  • 9
  • 19

3 Answers3

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.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
Romeo Ninov
  • 16,541
  • 5
  • 32
  • 44
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/
Edgar Magallon
  • 4,711
  • 2
  • 12
  • 27
-2

Another solution:

ln -s ${PWD}/f.txt /etc/
RonJohn
  • 1,015
  • 1
  • 12
  • 23