gdrive

From RaySoft

gdrive is a command line utility for uploading and downloading single files to your Google Drive. This tool on its own does not do synchronization of any kind, if you want that you can use googles own tool. It is meant for one-off uploads or downloads and integration with other unix tools. One use-case could be daily uploads of a backup archive for off-site storage.[1]

WARNING:
Unfortunately, this project is no longer maintained 😢 But there is hope with gdrive 3 🥳 Otherwise rclone is a good replacement that offers most of the features.

Documentation

Syntax

gdrive [GLOBAL-PARAMETER ...] SUBCOMMAND [PARAMETER ...]

Subcommand & Parameters

Global parameters
The following parameters can be used with the subcommands below:
-c FILE, --config FILE
Application FILE, default: ~/.gdrive.
list [PARAMETER ...]
List files and directories.
--absolute
Show absolute path to file.
-m NUMBER, --max NUMBER
Maximal NUMBER of files to list, default: 30.
--name-width WIDTH
WIDTH of name column, default: 40, minimum: 9, use 0 for full width.
--no-header
Do not show the header.
--order ORDER
Sort ORDER[2].
-q QUERY, --query QUERY
Search QUERY, default: "trashed = false and 'me' in owners".
mkdir [PARAMETER ...] PATH
Create directory.
-p ID, --parent ID
Parent ID of created directory, can be specified multiple times to give many parents.
share [PARAMETER ...] ID
Share a file or directory.
--revoke
Delete all sharing permissions (owner roles will be skipped).
--role ROLE
Share ROLE: owner/writer/commenter/reader, default: reader.
--type TYPE
Share TYPE: user/group/domain/anyone, default: anyone.
sync content [PARAMETER ...] ID
List content of syncable directory.
--no-header
Do not show the header.
--path-width WIDTH
Width of path column, default: 60, minimum: 9, use 0 for full width.
sync upload [PARAMETER ...] PATH ID
Sync local directory to drive.
--delete-extraneous
Delete extraneous remote files.
--keep-local
Keep local file when a conflict is encountered.
--keep-remote
Keep remote file when a conflict is encountered.
info ID
Show info of a file.

Queries

Field[3] Value type[4] Operators[3] Description[3]
name String contains, =, != Name of the file.
fullText String contains Full text of the file including name, description, content, and indexable text.
mimeType String contains, =, != MIME type of the file.
trashed Boolean =, != Whether the file is in the trash or not.
parents List in Whether the parents collection contains the specified ID.
visibility String =, != The visibility level of the file. Valid values are anyoneCanFind, anyoneWithLink, domainCanFind, domainWithLink, and limited.

Examples

Process the output of gdrive list in a loop
while IFS='|' read -r file_{id,name,type,size,created}; do
  echo "${file_name} ${file_created}"
done < <(
  gdrive list --max 100 --name-width 0 --no-header --order 'name' \
              --query "trashed = false and '<ID>' in parents" \
  | sed --regexp-extended 's/dir {6,}/dir||/; s/ {3,}/|/g'
)
Find all public available files and folders
gdrive list --query "visibility = 'anyoneWithLink' or visibility = 'anyoneCanFind'"
Get and test share status of a file
is_shared="$(gdrive info '<ID>' | sed --quiet '/^Shared:/ s/^[^:]\+: *// p')"

if [[ "${is_shared,,}" == 'true' ]]; then
  echo 'File is shared'
fi
Get the download link of a file and pipe it to Bitly URL Shortener
NOTE:
To shorten the download link the Python script shorten-url.py is used.
gdrive info '<ID>' \
| sed --quiet '/^DownloadUrl:/ s/^[^:]\+: *// p' \
| shorten-url -

References