For example: I have file
a.txt and file
b.txt. I want a link from
b.txt. If I open/read file
b.txt should open/read. If I try something like
ln -s a.txt b.txt I get an error because file
b.txt exist. How can I create a link from
You need to remove file
b.txt previously with command
rm b.txt, then create symbolic link with your command
ln -s a.txt b.txt.
You could use hard link from
a.txt, then execute
ln a.txt b.txt, both
b.txt would point the same file on hard drive and removing
a.txt doesn't remove file, which could be read through
b.txt. With symbolic link from
a.txt remove file and
b.txt symbolic link will be broken. More about hard links: https://en.wikipedia.org/wiki/Hard_link
Always check the man pages for help first. It'll save you a lot of time. Or if you're really busy, an
ln --help at the shell gives
Usage: ln [OPTION]... [-T] TARGET LINK_NAME (1st form) ....
Further down the help text, we find
... -s, --symbolic make symbolic links instead of hard links -f, --force remove existing destination files ...
which in a sense means, if you want to create a link for a file called
my_secret.link, you'll issue a command like
ln -sf my_secret.file my_secret.link
and if you do an
ls -l my_secret.link in here. You'll get something like this
lrwxrwxrwx 1 foouser groupbar 7 Jul 13 17:17 my_secret.link -> my_secret.file
The "l" in
lrwxrwxrwx tells us that its a link.
Edit : Rahul struck first.