How to Access iCloud Drive from Command Line in Mac OS

Nov 16, 2017 - 9 Comments

Access iCloud Drive from Terminal in Mac OS

Some Mac users may need to access iCloud Drive from the Terminal in Mac OS. But if you have tried to access iCloud Drive via command line on your own, you may have noticed it does not appear in the user Home directory. This is because iCloud Drive is actually locate elsewhere in Mac OS, and thus to access iCloud Drive from the command line you will need to dig around in the user Library folder instead of the Home folder.

We’ll show you the full path for iCloud Drive access from the command line in Mac OS, and show you how to quickly and easily get to iCloud folders and files from the Terminal.

This should go without saying, but you’ll obviously need iCloud Drive to be enabled on the Mac, and have an active internet connection. Without those prerequisites you would not be able to access iCloud Drive from the command line, let alone the Finder.

The iCloud Drive Path for Terminal in Mac OS

The command line path to iCloud Drive in Mac OS is as follows:

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

Remember, the “~” tilde is a shortcut for the current users home directory, but you can also choose to annunciate the entire path for a specific user folder if desired like so:

/Home/USERNAME/Library/Mobile\ Documents/com~apple~CloudDocs/

Note: You must have an active internet connection to access iCloud Drive and iCloud Drive files and documents.

How to Access iCloud Drive from the Command Line in Mac OS

To access iCloud Drive in the Terminal of Mac OS, simply use the familiar “cd” command and specify the directory of the iCloud documents path we detailed above. Thus the full command to access iCloud Drive via terminal would be as follows:

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

Hit the Return key and you’ll be in the iCloud Drive folder. You can confirm this by typing ‘ls’ and listing the contents of the iCloud Drive folder, or by typing ‘pwd’ to print the working directory.

Access iCloud Drive via command line in macOS

Of course most Mac users will just access iCloud Drive via the Finder by clicking on it in the sidebar or by going to the Go menu, but many advanced users will appreciate having direct command line access to iCloud Drive as well.

For what it’s worth, it was only several versions of Mac OS ago where iCloud documents and what became iCloud Drive were hidden from even the Finder too, and you had to access iCloud documents in the Finder via the same directory path in Mavericks that we just detailed above, whereas now with modern Mac OS releases there is a simple always accessible “iCloud Drive” item in the Finder sidebar of MacOS.

Copying Files to iCloud Drive via Terminal in Mac OS

Using the cp command you can copy files to iCloud Drive via Terminal, remember that by copying a file to iCloud Drive you are uploading it to iCloud Drive.

As an example, let’s say we’re going to copy a file named “test.zip” from the desktop to the main directory of iCloud Drive, the syntax would look like so:

cp ~/Desktop/test.zip ~/Library/Mobile\ Documents/com~apple~CloudDocs/

This is just like copying other files around in Terminal.

For most Mac users, copying files to iCloud Drive is easier from the Finder GUI of Mac OS, but it may be helpful for advanced users to use the command line approach.

Moving Files to iCloud Drive by Terminal in Mac OS

You can also move a file to iCloud Drive via the command line in Mac OS. Note that by moving a file to iCloud Drive, it will upload to iCloud Drive but then be removed from where it was originally on the local file system. This is achieved through the simple mv command. Let’s take the same example as above and move a file named test.zip from the desktop and move it to iCloud Drive.

mv ~/Desktop/test.zip ~/Library/Mobile\ Documents/com~apple~CloudDocs/

Again, this file has to upload to the iCloud server so it may take a while to complete the move.

For most users, moving files to iCloud Drive is easiest by Finder of Mac OS but again the command line approach is helpful to advanced users.

.

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS, Tips & Tricks

9 Comments

» Comments RSS Feed

  1. Ravi says:

    After we upload the files in iCloud Drive , I want to move them to photos in iCloud automatically using a command.
    And also I want to know what is the command to access the photos in iCloud directly.

    Hoping to get some solution for this.

  2. Nick says:

    Does anyone know how to get the capacity of the iCloud Drive from the command line?

    So far I tried df and it’s showing (similar) to what the capacity of my Macbook SSD has:
    [Nicholass-MacBook:idrive]$ df -h “$idrive”
    Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
    /dev/disk1s1 426Gi 131Gi 315Gi 30% 1313031 9221372036823442776 0% /
    [Nicholass-MacBook:idrive]$ echo $idrive
    /Users/np/Library/Mobile Documents/com~apple~CloudDocs

    I wondering if iCloud drive is just rsync to a local folder on the Mac’s local disk?

    Thanks

  3. Barb says:

    Way too complicated! All I want to do is see my photos taken on the iphone on my desktop.

    I’ll keep searching under spotlight to find another way.

    • the internet says:

      Barb, as the article specifically mentions this is for advanced users.

      Your pictures from an iPhone are never stored in iCloud Drive unless you save them there, in which case you could browse them through the Finder iCloud Drive viewer.

      Instead, iPhone pictures are saved in your iPhone Photos app. You have to manually download them to your Mac or PC computer, or you could enable the Icloud Photo Library feature which I would personally never recommend to anyone because not even Apple seems to know how it works. No photos will appear on your desktop unless you download them there.

  4. Sean says:

    Do you know if we can use versioned backups from the ” ~/Library/Mobile\ Documents/com~apple~CloudDocs/” directory in order to keep backups of our iCloud documents, in case seomething goes awry with docs in iCloud?

  5. Nando Vieira says:

    Just create an alias at your home folder and copy things there:

    ln -s $HOME/Library/Mobile\ Documents/com~apple~CloudDocs/ $HOME/iCloud

    Then you can copy files like

    cp whatever ~/iCloud/

    • Bernd says:

      The idea with the link is nice, but unfortunately you dont see the application‘s directories there (anyhow you also don‘t see them using the full path)

    • Cameron says:

      This is an excellent idea and helps tremendously to use iCloud more like other cloud providers.

  6. TD says:

    Why hide the iCloud folder away in some obscure location?

    iCloud is so difficult to use compared to Dropbox or even Google Drive. Getting the family sharing set up for iCloud was not easy. I finally said to heck with it and now I use Dropbox on all platforms my family uses. iCloud functionality has really been disappointing.

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site