5

I have a folder that I sync with online services such as Dropbox, that I sync to other computers with different operating systems. Part of my file/folder organization in this folder uses symlinks/aliases (my home computer is a Mac). When it syncs the folder to a Windows computer, unfortunately symlinks and aliases are not recognized, but shortcuts are.

Is there a way to create a symlink/shortcut once on a Mac or Windows with cross-platform compatibility? Otherwise I'll have to create two links per file, once for Mac/Linux and one for Windows.

NOTE: The purpose of this folder, because I know someone will ask, is to organize and store a lot of files in a hierarchy of folders. Occasionally, a file or folder seems to fit into two or more places, hence the symlink. This is a very common practice on Mac/Linux.

4
  • 1
    OSes and file systems are different so how can the symlinks be the same? Create separate symlinks for OS X and Windows.
    – Karan
    May 10, 2015 at 3:19
  • As long as I have the appropriate filesystem drivers, like NTFS-3G on my mac, it can ready pretty much anything on an NTFS drive except shortcuts. A folder, for instance is accessible via the NTFS drivers, as is a text file. Why not a shortcut?
    – tralston
    May 10, 2015 at 16:54
  • First of all, are you talking about Windows symlinks or shortcut (.LNK) files? I don't think NTFS-3G recognises the former. Secondly, of course shortcuts will be accessible on Linux like any other file, but without any program running to interpret them how do you suppose they will work?
    – Karan
    May 11, 2015 at 0:24
  • This isn't a solution, but it works well enough for my purposes. If I chose the Mac to create my alias of a folder/file, and then sync to Windows, the file is not functional in Windows. However, you can open it as a text file, and at least see the path to the file it's aliasing. At least this way, it's semi-readable if you are hunting for the aliased file later from a PC.
    – tralston
    May 12, 2015 at 23:00

1 Answer 1

6

According to this How-to-geek post, you can use mklink from cmd (Windows Vista - 10) to make symlinks that also work in linux. The guide also has a way to install an tool that can make linking easier (by adding it to the right-click menu.)

The command-line syntax for mklink is:

mklink /PARAM link_path existing_file_or_dir_path 

Where /PARAM can be:

/D – creates a soft symbolic link, which is similar to a standard shortcut in Windows. This is the default option, and mklink will use it if you do not enter an option.

/H – creates a hard link to a file

/J – creates a hard link to a directory or folder

An example that I just did:

mklink /J D:\Dropbox\school\14Winter\cs355 D:\Dropbox\school\classes\cs355

Which makes a link in 14Winter called cs355 to the existing folder cs355 in classes

After creating the link on Windows, the link worked on my Linux box, too. I have not tried Mac. If you find it doesn't work for mac, let me know.

NOTE: mklink is a cmd option and will not be recognized by PowerShell


OLD ANSWER: Python Script

Here is a dumb, but possibly useful solution: You could write a little python script that is an agnostic link (Code found here)

#!/usr/bin/python
import subprocess
import sys

if sys.platform == 'darwin':
    def openFolder(path):
        subprocess.check_call(['open', '--', path])
elif sys.platform == 'linux2':
    def openFolder(path):
        subprocess.check_call(['gnome-open', '--', path])
elif sys.platform == 'win32':
    def openFolder(path):
        subprocess.check_call(['explorer', path])

openFolder("relative/path")

Note: This will always open a new window.

3
  • Also, here's Microsoft's original* blog post announcing this feature: blogs.windows.com/windowsdeveloper/2016/12/02/… (*appears to be the original..) Sep 2, 2020 at 1:15
  • The default action of mklink is to create a file symbolic link; not the same as using /D parameter. /J creates a directory junction (which is quite similar to a symbolic link), not a "hard link" to a directory. Hard links apply to files only, and are really nothing more than directory entries.
    – kreemoweet
    Jan 22, 2022 at 3:13
  • @kreemoweet, According to the docs, /d is the default, thus it is the same thing... Also, according to the how-to-geek site, the /j junction is treated as a hard link on linux. If you have sources to back up your correction, I will gladly change it, but as of now I have no reason to trust you over those two sources.
    – Cory-G
    Jan 22, 2022 at 7:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .