What is the difference between a Symbolic Link and a Shortcut?
Related Unix.SE question: Is a symbolic/soft link similar to a shortcut/alias on a desktop?– Gaurang TandonOct 2, 2018 at 17:02
I think the important point is that shortcuts are just a file. They have a size (A small one, that just references where they point) and they require an application to support that filetype in order to be used.
A symbolic link is filesystem level, and everything sees it as the original file. An application needs no special support to use a symbolic link.
9Tree walking commands (anything like the unix utilities
du, etc) do need to know about symbolic links or they may do some very stupid things. For instance blinding following symbolic links can create cycles in the filesystem, and that is bad. Mar 6, 2011 at 20:50
12@dmckee; Very good point, while no application needs specific support to follow them, they do need specific support to not follow them!– PhoshiMar 6, 2011 at 21:19
Yes, don't need support to use them but do need to know about them. Mar 6, 2011 at 21:25
@Phoshi What exactly you mean by "and they require an application to support that filetype in order to be used.". Can you please explain with an example ?– GeekDec 10, 2012 at 13:48
8@Geek: A "shortcut" is effectively a file that holds the filepath of another file. When you read it, you read a specially formatted file that tells you where to look next. If your application doesn't listen, and simply reads the file verbatim, then you don't follow it. A symbolic link is filesystem-level, it's the filesystem itself that holds the "true" path to the data and when you attempt to access it, you retrieve the data pointed to.– PhoshiDec 12, 2012 at 13:12
A "Symbolic Link" can actually act like a substitute for a directory or file in a functional way, and is commonly used in Unix/Linux environments. Although there is apparently support for this in Windows, I haven't seen any actual use of it yet.
A "Shortcut" is just a regular file that has a reference to the destination file or directory along with some other things like the icon to be displayed. Unlike a Symbolic Link, you cannot "cd ./shortcut-name" in DOS (in Unix/Linux you can "cd ./symlink-name" and it will work just like a real sub-directory).
Also, in most Windows applications, when you click on a Shortcut in any File->Open GUI dialogue, your filename field gets populated with that shortcut's filename as well as it acting like a sub-directory, while in Unix/Linux the GUI treats a Symbolic Link as a path (without modifying the filename field).
1In Unix/Linux there are also "Hard Links" which are only ever applied to files (not directories). These are natural filename entries in the file system that just happen to point to the same file data as another filename entry somewhere else (doesn't have to be in the same directory). Mar 6, 2011 at 17:05
5@Randolf: 1) Hardlinks exist in Windows too. 2) One feature of shell shortcuts is automatic target tracking – if the target is moved, most of the time shortcuts will continue to work. (In an AD domain it's even possible to track files over computers; for example, if you move a HD elsewhere.) 3) One use of symlinks is redirecting a file or directory to an alternate location – they can point to files (unlike junctions) and directories (unlike hardlinks), cross filesystems (unlike hardlinks), and, AFAIK, can even point to network locations.– user1686Mar 6, 2011 at 17:46
Late comment, and I'm not sure if I just don't know what I'm doing with shorcuts, but I had to create a symbolic link instead of a shortcut for my vimrc file (I reference a dotfiles project that I use in a separate directory).– making3Feb 7, 2014 at 15:06
As others have mentioned, a symbolic link is one of the kinds of links available at the file system level, which makes it transparent to applications. I've found this documentation very helpful (esp. the "Crop/Unroll/Splice Outer Junctions/Symbolic Links" section). And the tool there looks nice too. (By mentioning this, and mklink, hopefully more searches will find this discussion.)
A shortcut is a file, not a real link, and it is generally only followed successfully as a link when interpreted by the Windows UI (user interface). For example, when you double-click on a folder shortcut, Windows redirects you to that other location. (This includes the generic File Open and File Save dialogs that most applications invoke.) On my desktop, I have a shortcut to this folder: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\G
The shorcut's filename is: C:\Users\user5\Desktop\Games.lnk, although Windows suppresses the .lnk extension and just shows "Games", even if you untick "hide extensions for known file types". But if you open a command prompt and do a dir, you'll see it:
C:\Users\user5\Desktop>dir "g*" Volume in drive C has no label. Volume Serial Number is 900... Directory of C:\Users\user5\Desktop 03/08/2014 05:30 PM 1,710 Games.lnk 1 File(s) 1,710 bytes 0 Dir(s) 246,818,222,080 bytes free
I can create the equivalent with a symlink by using the \D option (for directory):
C:\Users\user5\Desktop>mklink /D mysymlink "C:\ProgramData\Microsoft\Windows\S tart Menu\Programs\G" symbolic link created for mysymlink <<===>> C:\ProgramData\Microsoft\Windows\Sta rt Menu\Programs\G C:\Users\user5\Desktop>cd mysymlink C:\Users\user5\Desktop\mysymlink>
(A directory junction (\J) is an option too, since this is a folder link.) Windows explorer, just like this console and most applications, will let you browse "down into" this apparent subdirectory, rather than (a) redirecting "across" to a different location or (b) failing.
Shortcuts do not behave like subdirectories. I can invoke the Windows UI's default file behavior with this command (this opens the "G" folder in Windows Explorer):
Whereas mysymlink is listed (see the count) as a true subdirectory and can't be launched in that way:
C:\Users\user5\Desktop>dir "my*" Volume in drive C has no label. Volume Serial Number is 900... Directory of C:\Users\user5\Desktop 03/29/2014 06:08 PM <DIR> mysubdir 03/29/2014 05:40 PM <SYMLINKD> mysymlink [C:\ProgramData\Microsoft\Windo ws\Start Menu\Programs\G] 0 File(s) 0 bytes 2 Dir(s) 246,816,153,600 bytes free C:\Users\user57\Desktop>mysubdir 'mysubdir' is not recognized as an internal or external command, operable program or batch file. C:\Users\user57\Desktop>mysymlink 'mysymlink' is not recognized as an internal or external command, operable program or batch file.
Conversely, you cannot change-directory into a shortcut:
C:\Users\user5\Desktop>cd "Games.lnk" The directory name is invalid.
The Windows UI lets you right-click to edit a shortcut's properties. Or, the following shows exactly what is actually stored in the .lnk file (binary data), though a hex editor would display better:
Whereas trying to execute Notepad on an actual subfolder pops up an "Access is denied" error message, and an empty Notepad.
Conversely, if I make a file symlink (not a folder symlink), I can launch it with Notepad. Of the following notepad.exe calls, the first two work, and the third fails (it opens up the .LNK file, the binary gobbledegook).
C:\Users\user5\Desktop>mklink symplain.txt plain.txt symbolic link created for symplain.txt <<===>> plain.txt C:\Users\user5\Desktop>notepad.exe "symplain.txt" C:\Users\user5\Desktop>notepad.exe "plain.txt" C:\Users\user5\Desktop>notepad.exe "plain.txt.lnk"
This isn't just a console thing. Copying a shortcut to Notepad to my desktop and trying dragging and dropping each of the three onto it, it exhibits the exact same behavior. (Because drag and drop, unlike double click, lets the application interpret the shortcut.)
Regarding the differences between directory symlinks and junctions, see this discussion, and here's a very helpful description:
"A major difference in the way Windows resolves symbolic links and directory junctions is where the processing takes place. Windows processes symbolic links on the local system, even when they reference a location on a remote file server. Windows processes directory junctions that reference a remote file server on the server itself. Symbolic links on a server can therefore refer to locations that are only accessible from a client, like other client volumes, whereas directory junctions cannot. To address this, Windows Vista supports the new symbolic link type for both files and directories.
"Many file system commands have been updated to understand the implications of symbolic links. For example, the Delete command knows not to follow links, which would result in deletion of the target, but to delete the link instead. However, because not all applications may handle symbolic links correctly, creating a symbolic link requires the new Create Symbolic Link privilege that only administrators have by default."
"Symbolic Links differ from Shortcuts in that they offer a transparent* pathway to the desired data object, with a shortcut (.lnk), something has to read and interpret the content of the shortcut file and then open the file that it references (i.e. it is a two step process). When an application uses a symlink it gains immediate access to the data object referenced by the symlink (i.e. it is a one step process)."
Sometimes its good to have a functional example, so ill explain how I use this function.
I use google drive to backup files, but sometimes i want to backup files in a specific folder (I can't move them to ../google drive). Especially with windows 10 universal apps, config files and such are stored in appdata, and most of the time i cannot change this location.
I use windows native stikynot app, and i wanted to backup my notes, so i used a symlink here. Google drive recognizes the link as an actual file and syncs the files just fine, whilst the actual file is still in the appdata folder.
When I have files like project folders locally that I dont want to sync to the cloud I use shortcuts (copy, past->paste shortcut).