Published May 10, 2018 by

How to Upload a File to Google Drive from the Terminal/Command Line

We are doing several Linux projects regularly, and we will need to be sure we are backing them up. I wanted to quickly back up a copy of my files and so I went looking for an easy way to upload a file to Google Drive, and I found it with gdrive.

Here is the tutorial on how to upload a file to Google Drive from the command line or terminal.


1. Go to the root directory and download gdrive.
 # cd ~  
 # wget https://docs.google.com/uc?id=0B3X9GlR6EmbnWksyTEtCM0VfaFE&export=download  

2. You should see a file in your directory called something like uc?id=0B3X9GlR6EmbnWksyTEtCM0VfaFE. and rename this file to gdrive.
 # mv uc?id=0B3X9GlR6EmbnWksyTEtCM0VfaFE gdrive  

3. Give execute permission to gdrive.

 # chmod +x gdrive  

4. Install the file to /usr folder.

 # sduo install gdrive /usr/local/bin/gdrive  

5. Now we will need to give access to Google Drive to allow this program to connect to your account. To do this, insert below command.

 # gdrive list  

6. Copy the link it gives you to your browser and chooses your google drive account.


7. Click Allow button to give access.


8. Copy the generated verification code and insert into a terminal.


9. Now we are done... Let's upload a file.

 # gdrive upload /file_path  

For example,

 # gdrive upload /opt/subhash.txt  

10. Go to google drive and check it's uploaded.