Just Another Symbolic Link Article

This is another symbolic link article. I have previously written a short article on how to create symlink and hard links here. To read the other Unix and Linux link related articles, go here.

Symbolic Link:

The symbolic links indicate file paths (names). The paths can be both relative (my/dir) and absolute (/my/dir). By modifying: editing, removing, etc the target file, the symbolic link remains unchanged.

How to create a symbolic link: ln -s /path/to/file linkname

If you use relative paths for creating symlinks and move the entire directory stack, the symlink will not break.

Some operations on the symlink act on the targeted file. So, when you edit or change permissions of the symlinks, you change the permissions of the targeted file. Operations such as rename, move or delete, done on the symlink, act on the symlink (not on the targeted file).

Example with permissions:

$ ls -l link
lrwxrwxrwx 1 razvan razvan 6 2012-07-27 12:21 link -> myfile
$ chmod 444 link
$ ls -l link
lrwxrwxrwx 1 razvan razvan 6 2012-07-27 12:21 link -> myfile
$ ls -l myfile
-r--r--r-- 1 razvan razvan 0 2012-07-27 12:21 myfile

The size of a symlink is equal (in bytes) with the number of characters in the target file’s name.

Example:

$ touch myfile
$ ln -s myfile link
$ lrwxrwxrwx 1 razvan razvan 6 2012-07-27 12:21 link -> myfile

myfile has 6 characters in it’s name and the symlink’s size is 6 bytes.

How to find all the symbolic links pointing to a file:

You can use find for that: find -L . -xtype l -samefile myfile

$ ln -s myfile link
$ ln -s myfile link2
$ ln -s myfile link3
$ find -L . -xtype l -samefile myfile
./link3
./link2
./link

Symbolic Link versus Windows Shortcut:

There is a big difference between the Windows shortcuts and the symbolic links. The Windows shortcut cannot replace a program because of the Windows extensions, the lnk extension is not an executable. If you use GUI, the Windows shortcut behaves like the Linux symlink, but from a server standpoint, these two are quite different.

Liked it? Take a second to support Geekster on Patreon!
Tagged with: , , , , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Support LinuxG via Patreon
Support LinuxG.net on Patreon!
Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!