How to sync Google Drive from the command line on Linux

Google Drive is a cloud storage provided by Google, which allows file sync, file sharing and collaborative editing. As of this writing, Google offers Google Drive client software on multiple platforms: Windows, Mac OS X, Android and iOS. Notably, however, the official Linux client for Google Drive is still missing. So if you want to access Google Drive on Linux, you need to either access Google Drive on the web, or use existing unofficial Linux client software.

One such unofficial Linux client for Google Drive is Grive, an open-source command-line client for Google Drive. Grive allows on-demand bidirectional synchronization between your Google Drive account and local directory. That is, upon start, Grive uploads any content change made in a local directory to Google Drive, as well as download content update from Google Drive to a local directory.

In this tutorial, I will describe how to sync Google Drive from the command line by using Grive.

To install Grive on Ubuntu:

$ sudo add-apt-repository ppa:nilarimogard/webupd8
$ sudo apt-get update
$ sudo apt-get install grive

If you want to build Grive from source code, you can do the following.

$ sudo apt-get install cmake build-essential libgcrypt11-dev libjson0-dev libcurl4-openssl-dev libexpat1-dev libboost-filesystem-dev libboost-program-options-dev binutils-dev
$ wget http://www.lbreda.com/grive/_media/packages/0.2.0/grive-0.2.0.tar.gz
$ tar xvfvz grive-0.2.0.tar.gz
$ cd grive-0.2.0
$ cmake .
$ make
$ sudo make install

Now that Grive is installed, you can go ahead and launch it. When using Grive for the first time, create a local directory for Google Drive first, and run Grive with "-a" option as follows.

$ mkdir ~/google_drive
$ cd ~/google_drive
$ grive -a

The above command will print out the Google authentication URL, and prompt you to enter the authentication code.

To obtain the authentication code, open up a web browser, and copy and paste the Google authentication URL into the web browser bar. You will be asked to sign in to your Google account. Once you sign in to Google, you will be asked whether to give Grive a permission, as shown below. Click on "Allow access".

You will then see the authentication code created for you. Copy and paste the authentication code to the Grive prompt. Grive will go through authentication and start synchronizing folders and content between Google Drive and the local directory, as shown below.

Whenever you have made any change either in the local directory or Google Drive, you can sync Google Drive and the local directory by running Grive inside the local directory. Grive will automatically detect the change, and perform either downloading or uploading the diff.

$ cd ~/google_drive
$ grive

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

6 thoughts on “How to sync Google Drive from the command line on Linux

  1. Thanks for this article that I've just found. I'd love to be able to add Google Drive to my range of cloud storage, but I am almost exclusively using Linux. The above works well, but it doesn't appear to sync any subdirectories. Is this a known problem?

  2. The last release of Grive was a year ago, although there seems to be some recent activity with libraries and such. Is this program actually being maintained and developed? Any plans to add a GUI and real-time sync?

    • I don't know what the original author's plan was/is, but it seems there are some recent development efforts beyond Grive 0.3 in git repository. Has anyone tried that?

  3. I have been working on an alternative, having tried grive and found that it was terrible for a few reasons, but namely because it was slow and would crash trying to index huge file sets. I started working on an idea called GSync, which is essentially RSync for Google Drive. I intend to support all the same features of RSync.

    https://github.com/iwonbigbro/gsync

  4. and perform either downloading or uploading the diff???

    It deleted all my files. Grrrrr

    sync ./filename deleted in remote. deleting local
    sync ./filename deleted in remote. deleting local
    sync ./filename deleted in remote. deleting local
    sync ./filename deleted in remote. deleting local
    sync ./filename deleted in remote. deleting local
    sync ./filename deleted in remote. deleting local
    sync ./filename deleted in remote. deleting local

    • Luckily it moved the files into .trash

      The reason for deleting the files was that I moved the .grive and .grive_state files

Leave a comment

Your email address will not be published. Required fields are marked *

Current day month ye@r *