Is there a way to create a symlink whose target does not exist using shell scripts?
From reading man 1 ln
, I do not see an option to do so; and even -f
checks if the target exists.
Is there a way to achieve what I'm looking for?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityIs there a way to create a symlink whose target does not exist using shell scripts?
From reading man 1 ln
, I do not see an option to do so; and even -f
checks if the target exists.
Is there a way to achieve what I'm looking for?
When you run
ln -s nonexistenttarget link
ln
doesn’t check whether nonexistenttarget
exists, it creates the link, unless link
already exists. -f
works around the last part by deleting link
if necessary.
The impact of a non-existent target is only felt when a program tries to dereference the link, e.g. by opening it:
$ ls -l link
lrwxrwxrwx 1 steve steve 17 May 22 08:44 link -> nonexistenttarget
$ cat link
cat: link: No such file or directory
ln -s
command).
– Kusalananda♦
May 22 '19 at 7:02