MacOS – Symlink Google Drive

data synchronizationgooglegoogle-drivemacossymlink

I want to sync folders that are on my Mac to Google Drive, without having to drag the folders to the Google Drive folder and preserving my folder structure on my Mac.

I assumed you would have to have a symbolic link (symlink) for this to work.

So I tried in Terminal:

cd /path/to/google/drive
ln -s /path/to/folder/

The folder appeared on my Google Drive folder, but it did not want to sync.

So I then tried

ln -s “/path/to/folder”  “/path/to/google/drive/”

Still did not work. So I referred to this HowToGeek article about this topic and it said that you must move the original folder to the Google Drive folder and make a symbolic like to the original parent folder.

I'd like to have the original not in the Google Drive folder. Is there a free alternative to the symlink? I have looked at jdrivesync but had failed to install (that'll be another problem in another discussion).

Thanks for your help!

Best Answer

You can use a directory hard link, but only on HFS+ file system. You'll need GNU ln to use the -d option. This can be installed using Homebrew: brew install coreutils, then run:

sudo gln -d "/path/to/original" "/path/to/drive/folder"

You will be asked for your password. This command creates a hard link to the file/folder itself rather than how a symlink links to a pointer to a file/dir. As the link folder is essentially the same as the original folder, Google Drive syncs it correctly.

To unlink a hard link, use unlink "/path/to/drive/folder".

WARNING: APFS (Apple File System) does not support hard links. If you plan on installing macOS High Sierra or later and want to continue using directory hard links, you will need to maintain your HFS+ file system. By default macOS High Sierra intaller on a mac with SSD (e.g. without HDD or Fusion Drive) automatically converts HFS+ filesystem to APFS. To skip conversion during upgrade you will need to run the macOS installer as follows:

/Applications/Install\ macOS\ High\ Sierra.app/*/R*/startosinstall --converttoapfs NO

If you avoid the last option you will end up with mess of hard linked dirs in /.HFS+ Private Directory Data after the the upgrade.