How ToMac

Mac How To: Redirect a folder in your home directory with symbolic links

I’m the kind of person that likes to have all of his documents easily available on all of his computers. For this I choose to use Microsoft OneDrive. In Windows it’s very easy to change the location of my Documents, Photos, and Music folder to folders within the OneDrive directory so whenever a change is made to something or a file is added/deleted, these changes are automatically mirrored across all of my connected devices. It works great.

In Windows it’s simply a case of going onto properties dialogue for the folders in question, going to the ‘Location’ tab, and changing the location. You can just change the location from ‘C:\Users\Jon\Documents’ to ‘C:\Users\Jon\OneDrive\Documents’ on all of your computers and they will all automatically sync any changes you make.

Screen Shot 2015-07-24 at 12.29.29 copy

On Mac, however, it’s not so simple. OS X expects folders to be in their usual places in order to work properly so you’ll need to create symbolic links in Terminal in order to get all of your folders to sync. Symbolic links are essentially little shortcuts in your Home folder that OS X will see as your usual folders but instead they’ll be linked to somewhere else.

First of all you need to back up all of the data in the folders you want, the commands used in terminal will be permanent so you’ll need to ensure you have a backup of everything first (either a Time Machine backup/other service or simply copy and paste it somewhere else safe). As ever, please ensure you’ve read and agree to the disclaimer (linked here) before continuing.

Creating a symbolic link:

First of all you’ll need to open up Terminal (search for it with Spotlight or go into Applications -> Utilities -> Terminal).  Then you’ll need to change directory to the folder in question (in my case, Documents).

Do this by running the following command:

cd /Users/Jon/Documents/

Next you’ll need to check all of your documents are in the folder by running:

ls -al

Then you’ll need to move the contents of the folder into the folder you want (so in my case /Users/Jon/Documents to /Users/Jon/OneDrive/Documents):

mv -v * /Users/Jon/OneDrive/Documents/

Then run ls -al again to check the folder is empty. Terminal should just show . and .. (and probably .DS_Store). If it still has things in, you’ll need to move them out individually. mv -v doesn’t move files beginning with . so you’ll need to move them yourself with the following command (replacing .localized with the files you see listed):

mv -v .localized  /Users/Jon/OneDrive/Documents/

Next run ls -al again to check that all you see is: .DS_Store and . and …

Next you’ll need to do this to go up a level

cd ..

Then run this command to rename the old folder:

sudo mv Documents Documents.old

Then lastly, run this to set up the symbolic link:

sudo ln -fs /Users/Jon/OneDrive/Documents

Quickly run ls -al and you should see “Documents -> /Users/jon/OneDrive/Documents” listed there (with your folders, of course).

Jonathan Procter

Linux, Unix, and Windows server sysadmin.

Related Articles

Back to top button