I'm using https://github.com/prasmussen/gdrive


I'm trying to run a daily script that creates a folder in Google Drive and then uploads a bunch of tar archives in it. So far I can create the folder but can't upload if I don't have the id of the folder and I have no idea how to get it. For the time being, I'm uploading to a default folder and manually moving the files.

This is what I have so far


drive folder -t $(date '+%d-%m-%y') //makes the folder

for file in /home/backup/*.tar
drive upload -f "$file" -p (the newly created folder id)

2 Answers 2


According to your linked-to page, when you create a directory gdrive prints the id of it. Look at the example it gives:

$ gdrive mkdir gdrive-bin
Directory 0B3X9GlR6EmbnY1RLVTk5VUtOVkk created

So you can use, for example, awk to keep just the 2nd word and then provide this to the later upload commands:

dir=$(drive mkdir $(date '+%d-%m-%y') | awk '$3=="created"{print $2}')
: ${dir?}
for file in /home/backup/*.tar
do   drive upload -p "$dir" "$file"

The : ${dir?} stops the script if we fail to find an id.

  • Thanks for the example, helped me to capture the word i needed. It's the first time I need a bash script. Cheers
    – maiq
    Jul 29, 2016 at 8:49

you need to find the id of the folder where you want to upload the files I suggest you create the pas, for example type

$ gdrive ./gdrive list
1yJz6M094WNWVPoM09u2m8GjoLiumSdxl   Empresa                           0.0 B      2018-06-29 12:12:03   
1TS8b3JDx6RNeIvFN6HqAI9gNuNrs5D-b   Banco de Dados                    0.0 B      2018-06-29 12:11:42   
**1RYvaOGgf6E4HikDZ0cKKwoG-aShe6j6E**   Sistema                           0.0 B      2018-06-28 14:53:28   

copy the id of the folder where you que and paste after -p ex.:

dir = $ (drive mkdir $ (date '+% d-% m-% y') | awk '$ 3 == "created" {print $ 2}')
: $ {dir}
for file in /home/backup/*.tar
of the drive upload -p "$ dir" "$ file" **1yJz6M094WNWVPoM09u2m8GjoLiumSdxl**
  • 2
    I don't think your code is working. Can you revise it to make it executable?
    – Minix
    Jun 30, 2018 at 21:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.