soft links

A soft link is a file which says how to go to another file. When a program encounters a soft link, it will make a guess at whether it should ignore it, or try to get to that file.

To make a soft link to a file in the current directory, linking is easy:

1fortune > $file_1
2ln -s $file_1 $link_1

Now imagine your directory looks like this:

1dir_0/
2├── dir_1
3│   └── file_1
4├── dir_2
5│   └── file_1
6├── file_1
7└── link_1

Inside dir_1, making a soft link to dir_0/file_1 would mean putting the directions to that file:

1cd dir_1
2ln -s ../file_1 link_1

The real content of the file is just '../file_1, so making it from another directory would mean writing exactly the same address to that file:

1ln -s ../file_1 dir_2/link_2

Both symlinks are identical, except for the name.

1dir_0/
2├── dir_1
3│   ├── file_1
4│   └── link_1   <-- This one points to ../file_1
5├── dir_2
6│   ├── file_1
7│   └── link_2   <-- This one points to ../file_1 as well.
8└── file_2

Since it's just an address, you can delete the original file, then make another.

1rm file_1
2ls -l dir_1/
3fortune > file_1
4cat dir_2/link_2
5fortune | tee -a file_1
6cat dir_1/link_1

Last, let's make a link from dir_2/link_2 to dir_1/file_1 (this will delete the old link):

1ln -s -f ../dir_1/file_1 dir_2/link_2
2cat dir_2/link_2