Symbolic link to a non existing file
Asked Answered
F

1

14

I tried to create a symbolic link to a non existing file

ln -s non_existing_file.txt   $HOME/dir1/dir2/my_symbolic_link

Then I tried to write something in the non existing file using the symbolic link

vi $HOME/dir1/dir2/my_symbolic_link

Now after saving and exiting non_existing_file.txt is created under dir2.

Can someone explain why?

Filmdom answered 29/5, 2013 at 9:16 Comment(2)
Someone explain why is this question off-topic?Stonewall
This is not a programming question; it's a question about using the Unix environment; unix.stackexchange.com would be more appropriate.Stockbreeder
L
8
ln -s target linkpath

creates a symlink at linkpath which holds the name target. Operations on the symlink interpret the name target relative to the directory where the symlink resides, not the present working directory.

So, if you have a symlink holding, say, ../usr in /tmp/link-to-usr, then ls /tmp/link-to-usr will list the contents of /usr (which is /tmp/../usr) regardless of where the ls command is executed.

Luckily answered 29/5, 2013 at 9:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.