How to Access And Sync Google Drive In Ubuntu

grive-logoAfter much waiting, Google finally released the Google Drive last month. Together with the launch, Google also released desktop apps for the Windows and Mac OS. As for Linux users, once again, there is no love for you (yet). At the moment, you will have to use the web interface for downloading and uploading files. While many of us are patiently (or perhaps, impatiently) waiting for the official desktop sync client to arrive, there is a third party app, called Grive, that brings Google Drive synchronization to your desktop. It is a command-line based app, but the usage is easy and basic synchronization works fine. Let’s check out how you can access and sync Google Drive in Ubuntu.

Installation

Grive is a new project and it is not found in the Ubuntu repository. The most direct, though not the easiest, way to get Grive is to download the source code, compile and install it. Alternatively, an easier way is to use a third-party PPA that has added the Grive package into it. Here’s the PPA:

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

Usage and Configuration

1. Open your Nautilus File Manager and create a new folder and name it “gDrive” (or whatever name you want) in the Home directory.

2. Open a terminal and cd to the gDrive folder

cd gDrive

3. Run the grive configuration

grive -a

You should see the a long long URL in the terminal. Right click on it and select “Copy Link Address”.

grive-copy-link-address

4. Open a browser and paste the URL to the address bar (and press Enter). At the Google page, you need to grant access to Grive. Click “Allow Access”.

grive-allow-access

Once you allow access to Grive, it will show the authentication code which you need to copy and paste back to the terminal.

grive-authentication-code

5. Copy the authentication code and return to the terminal. Paste (using Ctrl + Shift + v) the code to the terminal and press Enter. Once it is authenticated, Grive will start to sync the gDrive folder and your Google Drive account.

6. For all future sync, you just have to run the command:

grive

in the gDrive folder. Note that you only have to use the “-a” parameter once. All future sync can be done without the “-a” parameter.

Automating the Sync

The current version of Grive doesn’t run as a background service to automatically sync your files. You will have to do it manually to perform the sync. One easy way to overcome this limitation is to create a cron job that runs the grive command at regular interval.

Here is how it can be done:

1. Open a terminal and type:

crontab -e

If prompted, select ’2′ for nano editor.

Scroll down to the end of the file and on a new line, enter the following command:

*/15 * * * * cd /home/damien/gDrive && grive

Save (Ctrl + o) and exit (Ctrl + x).

The above crontab will run the “grive” command in the gDrive folder every 15 minutes. You can change the time frequency and the file path to your own gDrive folder.

That’s it.

Do you like what you read here?

Receive the latest update in your inbox.

13 Comments

  • Enri

    There’s a little problem:
    if you put big file in your gDrive folder every 15 min a cron job let start grive.
    The first thing that grive check is if the big file is already stored on gDrive (and the response is no!).
    Then grive start the upload.
    After 15 min cron let’s start a new grive that check again if the big file is already on gDrive (and if the file is big maybe still not).
    Then restart the upload again… and so on every 15 min till the first cron operation finish the upload.

    Reply

  • eacp001

    May I suggest:

    */15 * * * * cd /home/damien/gDrive && pidof grive || grive

    A new instance will start when the first instance is done.

    Reply

  • Peter

    Here’s a techie guide I’ve written on how to make Grive sync automatically on local files changes. I think this guides periodic write up is the best way to sync remote changes.

    Cheers!

    Reply

  • reza

    nice job! there is only one 1 problem: when I add files to gDrive on my linux machine and then manually sync, no problem and I can see the files in my windows laptop promptly. But when I add to my Windows Gdrive folder (on my laptop), and then I sync on my Linux to access them, the command line strangely delete the remote file!! with this command:

    sync ./test_file_name.png deleted in local. deleting remote
    Finished!

    any idea why this happens?
    Reza

    Reply

  • Ouba

    You can also write a script with only a single line of code and put it in .gnome2/nautilus-scripts to enable manual sync from the File->scripts->name_of_your_script from the menubar or from the popup menu in the directory window of the file browser. I suggest to hard code the grive directory in this script to avoid it is invoked by error into an inapproriate directory from the menu.

    Reply

  • odoncaoa

    Nice Job Damien,

    As this article cuts to the core of practicality then, please extend that to it’s usable conclusion! Figure out an inverse working arrangement for any command line window from which you intend to capture, and include as graphics. The current version contains a giant black mass in it for step 3 (“Copy Link Address”), which makes it impossible to consider for printing!!!! It would end up using 20% of the ink that is presently in the printer cartridge in use; OUCH!!!!
    Slainte ;^)

    Reply

Leave a Reply