Cloud

How to access your local iCloud folder from the terminal

Working within the terminal window doesn't mean you can't keep your code, configuration files, or text files in sync with your iCloud account. Jack Wallen shows you how to make this easy.

machero.jpg
Image: Apple

If you're a macOS power user—especially a developer—chances are you use the terminal app. After all, it is a great tool for developing, scripting, working with configuration files, or just creating flat text notes. And since macOS comes complete with the Nano text editor, it's quite adept at filling a niche need.

But what if you want all of that terminal work to be saved to the cloud? Believe it or not, thanks to iCloud, it's pretty easy. Of course, this trick does require that you have your Apple iCloud account setup and working. Once you have that taken care of, you can sync all of your terminal work without much of a hassle, and without having to install third-party software.

How is this possible? It's all about working within the right directory.

Let me show you.

Your iCloud directory

Open up the terminal app and then issue the command:

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

The above command will change you into, you guessed it, your iCloud root folder. This is the folder that is synced with your iCloud account. At this point, you can create and edit text files that are then automatically saved to your cloud account. Once created, they can be accessed by any device that is connected to your iCloud account.

And that's all there is to it.

Or is there?

Let's make this a bit easier.

Creating a symlink

Instead of having to always change into that com~apple~CloudDocs directory, which can be a bit frustrating to remember that full path, we can create a symlink in your user home directory, such that you can simply type cd ~/iCloud to change into the correct directory. Here's what you do:

  1. Open the terminal app
  2. Change into your home directory with the command cd
  3. Create the symlink with the command ln -s ~/Library/Mobile\ Documents/com~apple~CloudDocs iCloud

With the symlink created, gaining access to the com~apple~CloudDocs directory only requires you enter the newly created symbolic link, with the command cd ~/iCloud.

You could even take this one step further and create a Dev folder (or whatever folder you need) within the com~apple~CloudDocs folder, to keep those files housed within their own directory. To do that, change into the iCloud folder and issue the command mkdir Dev. Once you've done that, you could then choose to create a symlink directly to the Dev folder, in the same fashion you created the symlink to the com~apple~CloudDocs folder. Or you could could go without creating the direct symlink to Dev and enter the directory by typing cd ~/iCloud/Dev.

NOTE: If you're already in your home directory, you can leave out the ~/ from the command, so changing into iCloud would require the command cd iCloud and changing into the Dev directory would be cd iCloud/Dev.

That's it. The next time you open up the terminal app, you can issue the command cd iCloud, and you're ready to work with any text files found on your iCloud account.

Making macOS even easier

The macOS platform does a great job of making it easy for the average user. With a bit of extra know-how, power users can enjoy a bit more efficiency and user-friendliness, even within the command line. Give this little trick a try and see if it doesn't make your work a bit easier and in sync.

Also See

About Jack Wallen

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.

Editor's Picks

Free Newsletters, In your Inbox