Access iCloud Drive via terminal

OS X 10.10 was just released, and one of the features I personally awaited the most was iCloud Drive. Unfortunately, I had to learn that it was not as accessible as Dropbox.

file ~/Dropbox
/Users/Ingwie/Dropbox/: directory

...but, iCloud Drive?

ls -1 Library/Mobile\ Documents/
./
../
.DS_Store
57T9237FN3~net~whatsapp~WhatsApp/
5U8NS4GX82~com~dayoneapp~dayone/
(...)

Does anybody know, how to correctly access iCloud Drive via terminal? Or is this simply not possible and only presented nicely by the Finder App?


Step One, Setup a Link to the iCloud Drive Folder actual path:

First, create a link in your home directory to your iCloud drive:

cd ~
ln -s ~/Library/Mobile\ Documents iCloud

The lines above do the following:

// brings you to home directory
// creates link to said path as the name, 'iCloud'

Typing cd ~/iCloud in terminal will now deliver you to this directory.

Step Two, Setup your Aliases in your Bash Profile:

Once, a link has been established, we need to setup an alias. Aliases are removed once we restart terminal, so we have to add an extra step where we edit a file called .bash_profile (or create one if we don't have one already).

Once done, we can simply type any binding and be delivered to our desired directory. In this example, we'll use i to take us right to our iCloud Documents folder.

We can create an alias to the iCloud Drive folder and save it in our bash profile as follows:

cd ~
ls -a

Look for a file called .bash_profile.

If you don't have .bash_profile, type:

sudo touch .bash_profile

Enter your admin password and press enter. (Note: adding sudo forces the terminal command to run as admin, thus the need to authenticate. Not adding sudo before the command may cause the command to be rejected due to user access privileges).

Once you have found .bash_profile, or finished creating it, we must now open it and define our alias inside as follows. Type:

sudo nano .bash_profile

You will again be prompted to enter you admin password. Enter it and press enter.

This will load up the nano editor. Press esc to be able to edit, and using the keyboard, arrow key down to the bottom. Type:

alias i="cd ~/iCloud/com~apple~CloudDocs/Documents"

Press Ctrl + O to save, and then enter, then press Ctrl + X to exit.

Your alias is now saved. If we had not edited our .bash_profile, and just typed the alias in terminal, it would be erased when we restarted terminal. Adding this command into our bash profile will prevent this.

Type your Alias in Terminal:

Now that you've saved your alias to your .bash_profile, we must finally execute our alias at least once (I tried not doing this and it didn't work), by re-typing our alias in the general terminal:

alias i="cd ~/iCloud/com~apple~CloudDocs/Documents"

This will create the alias, and will now work. If you restart terminal, and run your alias command again, it should also still work.

Results:

After this setup, we can simply type: i into the terminal, which will load our iCloud Drive\Documents directory.

Note: You can create any number of aliases to any folder, using any key binding you'd like, using the formula above. I just chose the Documents folder as this was the OP's question.

The above strategy was outlined in a tech blog article here: https://danielmiessler.com/blog/access-icloud-drive-terminal

Here's a tutorial on saving aliases to bash_profile (note sudo is not included in the write up, so if not working be sure to include): http://www.techradar.com/how-to/computing/apple/terminal-101-creating-aliases-for-commands-1305638

How I Set Mine Up:

I setup an alias called idev where by typing that in terminal, delivers me to a Development folder I created on my iCloud drive at:

~/iCloud/com~apple~CloudDocs/Development

Note, the line above is still using the link setup initially in Step One.

My personal Alias I setup is as follows:

alias idev="cd ~/iCloud/com~apple~CloudDocs/Development"

Using a link and then an alias can allow us to access the iCloud docs folder easily. The most confusing part is editing the .bash_profile file, but overall just follow the steps and now any time you open terminal your aliases should work!


You're correct in that the iCloud Drive directory is located within Mobile Documents. From your user's home directory, you can access iCloud Drive via terminal with:

cd ~/Library/Mobile\ Documents/com~apple~CloudDocs

Matthew is right; IF you have iCloud Drive turned on in sysPrefs, the iCloud Drive folder is there, he was just listing it relative to your user account.

I'm not sure about the "com.apple.CloudDocs" though. The com~ files & plists for everything, including mobile apps, are NOT visible in Finder -only in Terminal.

As of 10.10.1 if you're looking for the absolute path to the all-encompassing directory, try:

 /Users/username/Library/Mobile\ Documents

alternatively:

~/Library/Mobile\ Documents

To find the path to a file simply open the terminal (you can use the search tool), drag the file from finder in the terminal and it will provide you its path. This is however problematic with files in the iCloud Drive as apparently, the provided path does not work when trying to access it from other programs than the one it is registered with.


I created an Automator App that run this terminal command:

open ~/Library/Mobile\ Documents/com~apple~CloudDocs

You can download here. Just put it inside Applications and drag it to the dock.