79

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?

6

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 should absolutely not be using sudo to edit your local user's shell-profile files. – ELLIOTTCABLE Jun 5 '17 at 3:38
  • @ELLIOTCABLE (in all caps) Rather than just -1 me and give me your coy response, why not give me your rationale and the way YOU'D approach it, buy submitting YOUR answer below. – twknab Jun 6 '17 at 0:38
  • @ELLIOTCABLE Furthermore, the only way to edit my bash profile and save any changes I make to the file, is by using sudo to access the file as the admin. I've seen numerous examples of editing files this way and considering you just neg'd my answer without providing one of your own, I can't respect or accept the quality of your comment or answer. – twknab Jun 6 '17 at 0:41
104

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
  • 4
    Awesome! Gonna symlink that into my home folder so I can spot it faster. – Ingwie Phoenix Oct 17 '14 at 17:46
  • Has this moved? I don't even have a Library/Mobile\ Documents/ directory. – Joseph Hansen Dec 1 '14 at 17:47
  • @JosephHansen I'm not sure, on my system the Mobile Documents directory is still present as of OSX 10.10.1. – Matthew White Dec 7 '14 at 11:48
  • 2
    He has given a relative path here. Make sure you're in/at ~ before you copy pasta this into your terminal. – DigitalDesignDj Jan 21 '15 at 20:21
  • My mistake sorry, I'll update my answer. – Matthew White Oct 10 '15 at 12:31
6

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
2

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.

1

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.

1

I cannot write comments.

Because of the ~ the path have to be in "" to open. I created a symlink to access it more easy.

sudo mkdir /mounts
sudo cd /mounts
sudo ln -s "/Users/fusca/Library/Mobile Documents/com~apple~CloudDocs" iCloud

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.