Let's look now at how Linux manages soft blinks.
You know how when you install a program on windows,
you might get a shortcut on your desktop.
Now you double click on that shortcut and an application gets launched.
Now, the application is obviously not installed on your desktop.
It may have its files stored in C program files in my cool app directory.
And when you double click the shortcut,
this only points to an executable file at program files,
my cool app application dot exe.
So the double click on that shortcut basically redirects
you to the application dot exe which gets executed
soft links and Linux are very similar.
Now, a hard link is pointed to an I node,
but a soft link is nothing more than a file that points to a path. Instead
it's almost like a text file with a path to a file or directory inside
the syntax of the command to create a soft link,
which is also called a symbolic link is the same as before.
But we need to add the dash S or symbolic option,
for example, to create a symbolic link that points to the pictures.
And this is Ln dash
S path to the target path to the link file. Now, the path to the target is
our soft link will point to this path which is the location of a file or directory.
The path to the link file is our softlink file that will be created, for example,
to create a symbolic link that points to our family dog picture,
we can run the following command.
And now if we list files and directories in our long listing format with the LS
L command, we'll see output like this.
Now, the L at the beginning shows us that this is a soft link.
And LS dash L even displays the path that the soft link points to.
Now, if this path is long, LS dash L may not show the entire path.
An alternative command to see the path stored in a soft link
is readlink.
So in our case, it would be readlink, family dog shortcut.jp G.
Now you may also notice that all permission bits RWX seem to be enabled for this file.
That's because the permissions of the soft link do not matter.
Now, if you try to write to FSTAB shortcut,
this will be denied because of the permissions to the destination file apply.
And Etsy FSTAB does not allow regular users to write here
in our first command. We used an absolute path
slash home slash Aaron slash pictures, family underscore dog.jp G.
Now, if we ever change the directory name Erin in the future to something else,
this softlink will break
and you can see a broken link highlighted in red in the output of the LS dash L command.
Now to tackle this, you would create a soft link with a relative path.
Say for example, you were in the home directory of Aaron,
you could create a soft link using the relative path of the family dog file.
Instead of specifying the complete path.
When someone tries to read relative picture shortcut,
they get redirected to pictures slash family underscore dog.jp
G relative to the directory where the soft link is
now.
Since soft links are nothing more than paths pointing to a file,
you can also softlink to directories
or you can soft link to files and directories on a different file system.