OK, we take our last post back, Vista does have several exciting features to blog home about (and guys, for the last time, that comment’s what they call sarcasm!) one of which is the much requested “Symlinks” feature. It’s been in practically every other operating system for the past decade+ and is one of the most essential time-saving devices ever to be implemented. For those of you (Windows-dwelling creatures) that don’t know what a symlink is yet, here’s the Wikipedia definition.
Symlinks save tons of space by making files “pretend” to exist where they don’t, but even more importantly is the time they save by allowing you to create/reference a static filepath in all your programs – then have that “file” redirect to the real deal, no matter how often it changes. If you’re a web-dev kinda guy, think of it as mod_rewrite for your hard drive, without the PCRE libraries though… (come to think of it, the first OS to implement regex into symlinks has my vote!)
On Linux/BSD/Unix it’s called ln
:
CG@neosmart [~]# ln --help
Usage: ln [OPTION]... TARGET [LINK_NAME]
or: ln [OPTION]... TARGET... DIRECTORY
or: ln [OPTION]... --target-directory=DIRECTORY TARGET...
but if you’re reading this, you probably already knew that; or at the very least you know where you can find the man page.
On Windows, it’s a very similar procedure. Microsoft had long promised that symlinks would ship with Vista, and every build we’ve been enthusiastically entering the ln command and hoping to get something other than the dreaded
'ln' is not recognized as an internal or external command, operable program or batch file.
But it turns out that it’s been in there for a while — just hiding under a different name. It’s called mklink
(in keeping with the mkdir
nomenclature obviously), and it works just as well.
C:\Users\Computer Guru.NEOSMART>mklink
Creates a symbolic link.
MKLINK [[/D] | [/H] | [/J]] Link Target
/D Creates a directory symbolic link. Default is a file
symbolic link.
/H Creates a hard link instead of a symbolic link.
/J Creates a Directory Junction.
Link specifies the new symbolic link name.
Target specifies the path (relative or absolute) that the new link
refers to.
Now all Microsoft needs is to implement a mod_rewrite (or use one of the existing open-source implementations?) into IIS7 to suddenly kick-up the competition a notch…
Hat Tip: Thanks to Kristan Kenney!
Windows has actually had this ability since 2000, at least for directories. In Windows nomenclature, they are called junctions, and can be created using either the linkd tool from the resource kit, or junction.exe from SysInternals…
I admit, it might be nice to finally be able to symlink files though
Hey Cynic..
Actually, that’s a common misconception. “Junctions” in Windows 2000+ are actually hard links, and not symlinks as many people suppose.
There’s a fairly large gap between the two, and hard links offer few to none of the advantages of real symlinks. But Windows XP does have add-on (3rd party freeware) that adds Symlinks to the Kernel, but it’s not really reliable in my experience.
*OK, I can’t for the life of me find that freeware link that I saw while writing this article, but I’ll post back if/when I do.
Here’s the Wikipedia link on Symlinks and Hardlinks – a bit hard to spot the difference at first, but it’s there.
I know only Windows and I have to work on this tedious Solaris operating system for last 3 days. Can anybody tell me how to verify if a file/folder/service is systemlinked to /usr/local/bin? Say the binary “abc” is copied in /usr/local/xyz after installing a package and nowI need to know if “abc” is symlinked to /usr/local/bin or not. Please provide clear instructions like I am used to see in Windows Support manuals. It will be great, if you can mail me at krish3765@yahoo.com.
Hi,
Tedious solaris? Solaris is very good OS. Ok here you go. One thing is that you can search for all symlinks in the system and just grep for the /usr/local/bin or whatever you want. You can do all this in couple of unix commands.
find / -type l -exec ls -l {}\; >/tmp/all-sym-links-in-system
Now open the file to find what you are looking for.
–
Prem.
Ohh.. sorry.. mistyped the command
find / -type l -exec ls -l {}\; >/tmp/all-sym-links-in-system
Fixed it for you 🙂
Hi
I am not able to run a file after I created it by the mklink command.
Please refer to the steps below
1) i created a applocation file using
C:\>mklink foo notepad.exe
symbolic link created for foo <> notepad.exe
2)Then I tried to start the application using
C:\>start foo
At this point the system asked me to choose a program from the list of programs to run the file foo.
3)Next I tried to create the link using the following command
C:\>mklink foo.exe notepad.exe
symbolic link created for foo.exe <> notepad.exe
And then wen I gave Start foo.exe, I got the error message :
C:\>start foo.exe
The system cannot find the file C:\foo.exe.
You need to use the absolute path to notepad.exe
So it would something more like:
mklink foo.exe c:\windows\system32\notepad.exe
Is there any UI equivalent of creating symlinks with Vista – preferably via Explorer (e.g., right click drag a file to another explorer folder location)?
Here’s a UI implementation via Explorer shell extension that seems to work well with Vista symlinks: http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html
“come to think of it, the first OS to implement regex into symlinks has my vote!”
Oh Yes!
– mine too!
Once i write an Operating System, based on php and Javascript! 😉