93

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 Answers 6

15

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:

touch .bash_profile

Enter your admin password and press enter.

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

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: 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!

2
  • You should absolutely not be using sudo to edit your local user's shell-profile files. Jun 5, 2017 at 3:38
  • I think that @ELLIOTTCABLE 's point is that though your answer may be well-intentioned, the idea of using root privileges to edit text files in your home directory suggests that (forgive me) you don't know what you're doing, and taking advice from you could be dangerous. I'm sorry to put it that way, but hopefully you can take this as at least somewhat constructive. To others: please disregard this answer, and take a look at the answer that just tells you to cd to the directory. Make a symlink with ln -s if you like, that's a good idea (I claim). Sep 12, 2023 at 4:49
114

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

You must log in to answer this question.

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