Sync files to Google Drive from Linux – Command Line Utility

 

The Need
I wanted to sync some of my files to google drive easily. I wanted it to create folder structures on its own as well. I guess you have a gui utility for ubuntu but could not find an rpm file for fedora or a source. Also i wanted a Commang line utility, something like git.

The Solution
So i came across this lovely tool called grive2. Bingo. Perfect.

Installation
You can install it using the package manager. As simple as

dnf install grive2

(it should be listed as grive2.x86_64 : Google Drive client in your package manager)

Working it
Now that you have installed it how do you sync it. There are two steps to this process, the authentication step and the syncing step. Although it seems like a single step process when you first do it because when you do the authentication it automatically syncs it.

All you have to do is cd to the folder that you want to sync and then type in

grive -a

when you do that you will be prompted with a link along with an open prompt to paste an authentication code. Copy and paste that link in a browser and you will be asked to authenticate grive to access your google drive. Accept it and you will get the authentication code that you need. Copy this and paste it in your terminal where your prompt is waiting for you to come back. Then you are done.

grive is now looking at the current folder you are on and also your google drive to see if the content/folders in the current folder are already there. Since this is your first time there is no chance that it is already there so it uploads all that is in the current folder to google drive. Once that is done it starts downloading what is in google drive to the current folder since you don’t already have those here. Syncing is a two way road, both uploads and downloads happen.

The next time you sync you just need to go to the same folder and say

grive

and it does the same without any authentication

Type in grive --help for more options

grive

Tricky Bit – Being Specific
Now is the tricky bit. I did not need these downloads to happen. My want was very specific. I just wanted to sync what is in a particular folder of mine in my pc up to google drive and then in the future when ever i made changes to “this particular folder” in my local drive or google drive i wanted it to sync that. Many of you might want the same too. You would have loads of stuff on your google drive. Why sync everything!

So the way around this is the mighty ‘-s’ parameter that lets you specify a specific folder that you wanted to sync. So what did i do.

Example say that my folder, lets call it MyFolder is in home/me/Documents. This MyFolder of mine contains all the files that i want to sync to grive. Then what i would do is cd to Documents and do

grive -a -s MyFolder/

Now this would authenticate this folder(Documents) but only sync the MyFolder folder. Again, when i want to sync this folder again i would go to Documents and say

grive -s MyFolder/

it would now sync what ever changes i made whether in my local or in my server, deleting and uploading as necessary. “Deleting and Uploading as necessary” is one of my favorite aspects. Although thats what syncing is. Ironic. πŸ™‚

Wonderful!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s