How to access your Google Drive account from Linux command line using Gdrive

While Google Drive is no doubt one of the most popular (if not the most popular) cloud storage services available today, what's really sad is that there is no official Drive client available for Linux. But that doesn't mean there are no alternatives - in fact the awesome Linux/open-source community has developed several unofficial Google Drive clients, some of which we've already discussed here at HowtoForge.

Expanding our coverage on such clients, in this article we will discuss another tool, dubbed Gdrive. Please note that all the instructions and commands mentioned in this write-up have been tested on Ubuntu 16.04.


Gdrive is basically a tool that lets you access your Google Drive account through the command line. Yes, that means you need to run commands for any and every Drive operation that you want to perform. But worry not, it's not at all difficult to use and the commands aren't difficult to remember either.

Gdrive Download, Installation, and Setup

You can easily download and install Gdrive on your Linux box by heading to the tool's official GitHub page, and downloading the executable file for your system. For example, I downloaded a file named gdrive-linux-386 as I work on a 32-bit Linux distribution.

Once downloaded, make sure that the file has executable permissions. If not, grant it the permissions through the chmod command. For example, I used the following command:

chmod +x gdrive-linux-386

After this, you need to make sure that the tool is allowed to connect to your Google Drive account. For this, you need to run the executable file with about argument. Here's the command:

./gdrive-linux-386 about

You will be asked to enter a verification code, which is obtained by heading to the url printed in the command's output and authenticating with the google account for the drive you want access to. The following screenshots will make the process clear:

Starting Gdrive

Gdrive UI

Clicking the 'Allow' button will produce the required code on the web page itself. After the verification code is entered on the command line terminal, Gdrive will connect to your Google Drive account. For example, here is the complete output after I entered the code in my case:

Gdrive connected

Important note: The aforementioned authentication process will create a token file inside a folder - named .gdrive - located in your home directory. "Note that anyone with access to this file will also have access to your google drive," the tool's official documentation says.

Using Gdrive

Here are examples of some of the basic Google Drive operations that you can carry out using Gdrive. I am assuming that the Gdrive executable that you download on your system is also named gdrive-linux-386 and is kept in your current working directory.

List contents

To list the contents (files and directories) of your Google Drive, you can use the following command:

./gdrive-linux-386 list

If you want to limit the maximum number of files that can be displayed in the output (default is 30), you can add the -m flag followed a number that represents the new maximum limit. For example:

./gdrive-linux-386 list -m 10

You can also add a query for filtering the output based on your requirement. For example, If I only want specific files (say, that contain 'Gmail' in their name) in the output, I can use the following command:

./gdrive-linux-386 list -m 10 --query "name contains 'gmail'"

Here's the output of the above command on my system:

Gdrive search query

Download and upload files

Given that Google Drive is a cloud storage service, so needless to say that you'll want to use Gdrive to upload and download files to/from your Drive account. Here's how you can do these operations:

To upload a file, run the following command:

./gdrive-linux-386 upload [file-name]

To upload a file to a specific directory, use the following command:

./gdrive-linux-386 upload --parent [dir ID] [filename]

The directory ID ([dir ID] in the command above) can be obtained from the entry of that particular directory when you list your Drive contents using Gdrive.

To create a new directory in your Google Drive, use the following command:

./gdrive-linux-386 mkdir [directory-name]

Of course, you can create a new directory and then use its ID to upload a file to it.

Finally, you can use the following command to download a file from your Google Drive account to your system:

./gdrive-linux-386 download [file-name]

There are several flags that help you with your download operations. For example, -f tells Gdrive to overwrite existing file of the same name (if any), -r tells the tool to download a directory recursively, and --delete makes sure the remote file gets deleted when download is successful. It's worth mentioning that the last two flags also work with upload operations.

Share files

Gdrive also lets you share your Google Drive files with others. For example, if you want to make a file readable to everyone, you can do it through the following command:

./gdrive-linux-386 share [file ID]

Of course, that's not what we always want. Mostly, we share files with our friends or colleagues. So, for example, if you want to share a file with someone you know, you can do so using the following command:

./gdrive-linux-386 share [file ID] --type user --email [email add]

The above command will grant reader permission to your friend, whose email address you have to provide in place of [email add]. If you want to grant, say, writing or commenting permission, or even want to transfer the ownership, then you'll have to use the --role flag. Accepted values for this flag include 'owner', 'writer', 'commenter', and 'reader'.

Here's an example of how I used this command to share a file with one of my friends as well as grant write permission to them.

Share a file with Gdrive

Show file info

Gdrive also lets you access information related to any of your Google Drive files. Here's the command for it:

./gdrive-linux-386 info [file ID]

Here's an example:

Gdrive show file info

For more Gdrive commands as well as details on how the tool works, head to the project's official GitHub page.


What I liked about Gdrive is the ease with which it can be downloaded and installed, as well as the detailed documentation available on the tool's GitHub project page. And not to mention the easy-to-remember commands. However, on the flip side, the documentation itself says that "the current implementation is slow and uses a lot of memory," meaning there's a good scope of improvement.

Share this page:

Suggested articles

26 Comment(s)

Add comment



Thank you. This is the first article I have read about how to access Google Drive from the Linux command line that is concise, to the point, and leads to useful results.

By: zacharias

Perfect article! Tried to upload files to Google Drive a few months ago, ... without success. Today I found your article and it was exactly what I was looking for. Thank you!


By: wl999


By: phhpro

At last! I was about to abandon GDrive and all that caml stuff when I found this one. Works like a charm, albeit I have yet to figure how to list a given sub folder. Anyone know if that's a feature? Thanks for the post, much appreciated! 

By: Monster

Thank you for this great article. I think -or expect- to implement gdrive in a shell script soon. How long does the auth code last once you activate it? Hours, days, weeks? As the implementation is likely going ton end on a headless server, I was wondering what to do after the auth code expired.

Any advice please?

By: sundar

Hi, Good day! Did you get answer for the auth code question? I am having same trouble where my script is going to run in a headless server and I am wondering if someone figured out on the auth code.


i want to download things from the web directly to google drive.  is there a way for that?

By: Tanvi Agarwal

How to get the  from gdrive?

By: Waqar Afridi

Nice Article, My Question is that is grive two way sync? Does it also sync the files on my google drive to my local PC? If yes, is there any way to turn this off? I want one way sync, from my PC to google Drive.

By: Martin crysman Zahradník


if you want to effectively support official GNU/Linuxo Google Drive client, I suggest pushing (upvoting) officially in (CCC) in Future Ideas section. There are already several posts addressing this issue, but they haven’t got many upvotes, recently, most voted project has got some 280 upvotes, those linux client posts just some 80 - we need to support them and pull them up.



I don’t understand how a company (Google) having a world-wide success with Linux-kernel-based operating system (Android) can support Microsoft Windows in such a showy way, and do not provide a for-a-soo-loong-promised official Drive client for another Linux-kernel-based OS (various GNU/Linux operating systems such as Debian, Fedora, Arch, Ubuntu and many of their derivates).

In our company, we’ve been using several GNU/Linux machines, and we are planning to deploy them even more, instead of Windows OS. Not having official Google Drive client is just another obstacle in deploying opensource/FOSS solutions :/


If you are a GSuite administrator, you may help by upvoting here:

and/or here:

and/or here:

and/or here:

and/or here:


Thanks a lot!




By: dodolong

Thank you very much ^_^.

By: Matt

This is a great guide.  How do I access files shared in a Teams drive?

By: Scott

Good question!!!

By: akshay jain

i want only the file id  that i upload or i only want to fetch the id for either file or folder so what is the way to do this.

gdrive is failing more and more over time. I started with about 80% success rate on the commands I ran, but it's been getting worse over time. Im down today with 100% failure to run any commands. Just keeps reporting that the rate is too high, or returns a 1 exit code.

By: Lokesh

How to sync folder if it is uploaded once ? I used upload command and it create duplicate directory.

By: whatever

You are running the commands too often. There is ratelimiting on the API and that is completely normal. It's not a problem of the tool, it is a problem with how often you send requests. The google drive API isn't meant for heavy loads of automation.

By: CP

Great tutorial. All worked except when I want download a file to my Linux latop I am having to use the file-id not the file name. If I use the filename I get a 404 error, file not found. But when I upload it works with the filename. Is that right?


Any way to download multiple files using this? Like can I specify two ids such that they'll be downloaded one after the other

By: Prokhor

Used to use this quite a bit, but looks like it is down (as of November 2019). The authentication step redirects to a Google page saying "temporarily disabled for this app". Commenters on the github page say re-compiling with your own API keys should still work (little more complicated). 

By: Jens Kisters

I get "Logging in with google for this application has temporarily been disabled. The usage of this app with google Log-in has not yet been confirmed."


By: Chanra

Sign in with Google temporarily disabled for this app

When i try to get Verification Code with gdrive aboutand pasting url to the browser and than login, i've got the following error ;

Sign in with Google temporarily disabled for this appThis app has not been verified yet by Google in order to use Google Sign In.

By: silensho

As of February 25th, 2020, the verification code can't be obtained. Like previous comments stated, Google displays a warning message for the URL, nothing else. I did not have a chance to use it. I guess it was good while it lasted.

By: Silent

It's 13 Apr 2020 and still no code can be obtained

By: dpc

 When trying to authenticate with my google account I get this error page "This app tried to access sensitive info in your Google Account. To keep your account safe, Google blocked this access."

anyone know how to allow this or have a work around?

By: Pansmanser

This works fine, as far as it goes. I'd really like to be able to access a Google-Sheets spreadsheet directly from libreoffice (or any other app). Is this possible?