Pushpinder Singh Grewal Pushpinder Singh Grewal - 1 year ago 67
Java Question

Difference between symbolic links and shortcuts

What is the difference between symbolic links and shortcuts?

As I was reading Oracle's Documentation on java.nio.file package, there I came to know about symbolic links. At first, I thought they are talking about shortcuts because at first they both appeared the same to me. But later I realised that I am kind of assuming this without a proof so i googled it and found some links about the differences between the two. But I couldn't get a clear view of what these actually are as the answers were not that good. I hope I can get an explanation here!

Answer Source

A symbolic link is a special file which references another path on disk. If an application opens this file (or includes it in a path), the operating system will silently follow the link.

For instance, assume you have a symbolic link l which points to a directory d with a file file in it. Observe:

$ ls d/
$ ls l/
$ touch l/file2  # Create a new file in the path under l
$ ls d/
file  file2

Symbolic links (symlinks) are a feature of the filesystem part of the operating system. They can be used by any application; applications that do want to treat symlinks differently (such as backup programs, which must not blindly follow symlinks lest the number of files becomes infinite) need to take special precaution to do so.

In contrast, a shortcut is a regular file which is rendered differently by the user interface(UI). A shortcut file also contains the desired target path, but can contain additional information, such as an icon, command-line arguments, instructions to the UI to run the destination as another user, categorization of the destination, translation information and the like. For an application, a shortcut is a regular file whose contents describe the shortcut. For instance, if you open a .desktop file with an editor, you'll see information like

Exec=libreoffice --calc %U

You should generally use shortcuts if you want to add an entry to the user interface (typically the graphical parts). Shortcuts allow you extended customization - for instance, Danish users will see Regneark, and English users Spreadsheet in the above example.

If, on the other hand, you want the alias to be visible to all applications, go for a symlink instead. For instance, you could have a legacy name of a file that some applications expect, or one application that can do multiple things, or the current version of a project directory.

Note that some systems do not support symlinks, and some have no use for shortcuts. If there is no graphical interface present (for instance a home router without a monitor attached), shortcuts would not be useful. On the other hand, symlinks require support by the filesystem (FAT has none) as well as the opreating system (DOS/old versions of Windows lack support).