Using Windows 7 Symlinks

I ran into a problem with integrating my web development/design projects on my computer with my local webserver. To further explain:

  • I keep all my professional work, including client files, on a separate hard drive partition so that I can easily and regularly back them up, let’s call it g:\
  • Client files for web projects are organized as such: g:\clients\client-name\project-name , so that if a long-term client wants a site redesign, I can easily keep these separate rather than dumping them into a single public_html directory for each client
  • My local testing server is pointed at a different partition, let’s call it h:\
  • I want to be able to serve individual projects via the testing server, but only work on the project files

I thought of the *nix ln -s command, but was then running Windows 7 so I tried shortcuts. Didn’t work. After a little digging, I found the solution to be symlinks in the cli. There are equivalents in most OSes, though fair warning: in OSX, there are GUI aliases (which effectively behave as a symlink) and cli aliases, which are typically user-defined shortcuts for running various common commands or tasks – thanks for the correction, mystery commenter. From the Windows 7 command line, type the following, changing the directory paths as needed:

mklink /D H:\target\directory\linkname G:\clients\client-name\project-name

In Windows 7, mklink /D option specifies to create a symbolic link to/from a directory (the default is a file symbolic link); the equivalent  *nix ln -s source target command depends on the user pointing the specified source to a matching target. The next part of the command is the first argument, the new target directory where you want the link to be placed. After that is the source directory – the directory mklink will use as its source. Oh, and if you have problems running mklink, try right-clicking the command prompt shortcut, and select run as administrator. More info here.

For the most part, easy as pie.

Be careful when deleting/creating content in these directories – the linked directory allows you to manipulate files in the source directory!

2 thoughts on “Using Windows 7 Symlinks

  1. actually,

    symlinks are the windows equivalent of unix symlinks. unix aliases are something altogether different. aliases are a way of creating command-line shortcuts. e.g.

    $ alias dir = ls -la

Leave a Reply