So using ln -s to make a link will make either a relative link (link->../file) or an absolute link (link->/home/user/dir1/file).

But sometimes I don't want to type the entire absolute path, but still need an absolute link. Maybe I want to link link->../dir2/file but I really want link->/home/user/dir/another dir/a third dir/dir6/dir2/long named dir/dir/dir2/file. That's a lot of typing.

What's an easier way to do that then this?

ln -s "/home/user/dir/another dir/a third dir/dir6/dir2/long named dir/dir/dir2/file" link

Thanks, my fingers appreciate it.

  • One way to avoid typing too much is to use «tab». It will still be more typing than you are hopping for. But also works in more situations. – ctrl-alt-delor Jul 30 at 9:06

Okay, I found one way to make it work easily:

ln -s `realpath ../dir2/file` link       #not perfect

It's not perfect - $( ... ) is preferred to `...` for command substitution, and there's a problem with filenames with spaces - the "double quotes" fix that while allowing command substitution to proceed. So here is an updated answer:

ln -s "$(realpath ../dir2/file)" link

So if I want the filename to be the same,

ln -s "$(realpath ../dir2/file)" .
  • Note: $(command) is preferred over back ticks, and see symlinks tool. – ctrl-alt-delor Jul 27 at 15:36
  • Is symlinks a windows tool? – Peter Kay Jul 29 at 19:05
  • No it is command line. – ctrl-alt-delor Jul 30 at 9:01
  • Wow, I am not finding any documentation for it anywhere. Could you provide a link? – Peter Kay Jul 30 at 15:40
  • on Debian, install with apt install sysmlinks. It says that it was written my “Mark Lord”. Hope that helps. Also see man page – ctrl-alt-delor Jul 30 at 19:08

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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