Certain Mac users will face the need to use iCloud Drive from the Terminal of the Mac OS. Any such user will have noticed that when trying to access the iCloud Drive in this manner that it does not appear in the user Home directory. The reason for this is that iCloud Drive actually appears someplace else in the MacOS directory. So, to access iCloud Drive from Terminal it is necessary to browse around in the user Library folder instead of the Home folder.
Before starting, you should of course enable the iCloud Drive on Mac and have a stable internet connection. Without these requirements fulfilled it won’t be possible to carry out the whole procedure.
How to Open iCloud Drive Via Terminal on Mac
The command line path to the iCloud Drive in the Mac OS is:
~/Library/Mobile\ Documents/com~apple~CloudDocs/
The ~ is a shortcut for current users home directory but can also be used to annunciate the entire path to a specific folder if you wish. An example of this is:
/Home/Your-Username/Library/Mobile\ Documents/com~apple~CloudDocs/
Now, in order to access the iCloud Drive from the Mac OS Terminal use the ‘cd’ command and specify the directory of the iCloud documents path as mentioned above. The full command to access iCloud Drive from Terminal is:
cd ~/Library/Mobile\ Documents/com~apple~CloudDocs/
Press the Return key to come to the iCloud Drive folder and confirm by typing ‘Is’ which will list the contents of the iCloud Drive folder. Alternatively you can type ‘pwd’ to print the working directory.
Most Mac users can access the iCloud Drive simply through the Finder by clicking on it in the sidebar or going to the Go menu but advanced users will also like using the command line to do so in a more direct manner.
Copy Files to iCloud Drive from Terminal
The cp command can be used to copy files to the iCloud Drive. For instance, if you want to copy a file named ‘photos.zip’ from desktop to the directory for iCloud Drive, all you need to do is enter the following command:
cp ~/Desktop/photos.zip~/Library/Mobile\Documents/com~apple~CloudDocs/
This is similar to copying other files around the Terminal.
See Also: How to Shutdown your Mac from Terminal
Move Files to iCloud Drive from Terminal
Similarly, it is possible to move a file to the iCloud Drive through the command line as well. It will upload to iCloud Drive but then be removed from wherever it was originally in the file system. This can be done by using the mv command and it is quite easy to perform. Just use the below given command for a test file:
mv ~/Desktop/photos.zip ~/Library/Mobile\ Documents/com~apple~CloudDocs/
Keep in mind that this procedure involves the file being uploaded to the iCloud server so it could take some time for it to complete. What do you think of this method as compared to simply using the Finder of Mac OS?