If you are decent user of Google Drive and also find yourself frequently in a linux terminal, you’d probably like to be able to interact with your content on Google Drive from CLI.
It’s easy to imagine how useful it would be to list and upload files to your Google Drive directly from your shell.
Looking into how to send some archives to Google Drive from linux CLI, I found gdrive.
This is not Google’s implementation for linux but a tool written in Go by Peter Rasmussen. Gdrive 2 uses version 3 of the Google drive api and it’s compatible with gdrive 1, according to the information on the github project.
Also, it has no dependencies and it is available for Windows and Mac as well! For more info definitely check: https://github.com/prasmussen/gdrive
In this post I will only show how easy it is to install and use it on linux.
- Download gdrive 2 binary for Linux x64:
- Install the binary in your system so that it is in the PATH:
Note: there is a bug in the version displayed at this moment (https://github.com/prasmussen/gdrive/issues/143) The version the binary returns to ‘gdrive version’ command is 2.0.1 but the binary is supposed to be for version 2.1.0.
At this moment the /usr/local/bin/ directory looks like this:
I used the version in the binary name and the symlink so that I can install a newer version later and activate it (by updating the symlink) while keeping the current version available in case I need to roll back.
Once this is done, we need to configure it:
Then use the URL above in a browser to get the token for authentication. Once you have the code go back to the terminal and paste it in:
The token was saved into ~/.gdrive/ folder in a json file. It is important to know this because:
-
If this folder does not exist, the next time gdrive is run, it will go through the above process to help you get a token.
-
Whoever has access to your token can also access your Google Drive!
So make sure the permissions and ownership are set properly; They should be correct by default, but in case they are not:
Extra:
-
if you need to configure access to more then one Google Drive, you can set the environment variable GDRIVE_CONFIG_DIR to point to anoter config directory - if this new directory does not exist, gdrive will prompt again for authentication/configuration
-
the communication to your Google Drive is over https - just in case you were wandering if anyone can easily see your traffic