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
$ 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.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

9 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.

    • Hi Craig,
      What stage of development is Gsync at? I need to get away from Grive as it is unreliable and slows my system significantly. I can't find much out about Gsync, but it sounds promising. Is it reliable?

      Thanks, Aldous

  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

  5. I started using Grive a month ago or so. I set it up on two laptops, and have both doing it automatically using crontab scheduled jobs. I seemed to work as planned. If I added, changed, or deleted a file on one laptop it was added, changed, or deleted in Google Drive and eventually on the other laptop too. Sweet!

    Recently we had a project that required moving a lot of files. I have seen web posts about Grive having issues with moving files, plus my wife sometimes suspends her laptop before Grive has run. We ended up with a mess! It was putting moved or deleted files back, and eventually quit running entirely. I don't see a "force a new upload from scratch" switch in the documentation.

    I think we are toast, and am looking at going to insync, which appears to be a one time $15 charge for personal use.

    I wish Google would support Linux better. They have had several projects now where Linux support was dropped, or never started. Picasa in another example.

Leave a comment

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