drive is a tiny program to pull or push Google Drive files.
drive was originally developed by Burcu Dogan while working on the Google Drive team. This repository contains the latest version of the code, as she is no longer able to maintain it.
Table of Contents
- De Initializing
- Sharing and Emailing
- Trashing and Untrashing
- Emptying the Trash
- Listing Files
- Stating Files
- Retrieving md5 checksums
- New File
- Command Aliases
- Index Prune
- Revoking Account Access
- Applying patches
- Why another Google Drive client?
- Known issues
- Reach out
go 1.3.X or higher is required. See here for installation instructions and platform installers.
- Make sure to set your GOPATH in your env, .bashrc or .bash_profile file. If you have not yet set it, you can do so like this:
$ cat << ! >> ~/.bashrc > export GOPATH=\$HOME/gopath > export PATH=\$GOPATH:\$GOPATH/bin:\$PATH > ! $ source ~/.bashrc # To reload the settings and get the newly set ones # Or open a fresh terminal
The above setup will ensure that the drive binary after compilation can be invoked from your current path.
To install from the latest source, run:
$ go get -u github.com/odeke-em/drive/cmd/drive
- In order to address issue #138, where debug information should be bundled with the binary, you'll need to run:
$ go get github.com/odeke-em/drive/drive-gen && drive-gen
$ go get -u github.com/odeke-em/drive/drive-google
That should produce a binary
To bundle debug information with the binary, you can run:
$ go get -u github.com/odeke-em/drive/drive-gen && drive-gen drive-google
- Using godep
$ cd $GOPATH/src/github.com/odeke-em/drive/drive-gen && godep save
- Unravelling/Restoring dependencies
$ cd $GOPATH/src/github.com/odeke-em/drive/drive-gen && godep restore
Please see file
drive-gen/README.md for more information.
For curated packages on your favorite platform, please see file Platform Packages.md.
Is your platform missing a package? Feel free to prepare / contribute an installation package and then submit a PR to add it in.
Optionally set the
GOOGLE_API_CLIENT_SECRET environment variables to use your own API keys.
Before you can use
drive, you'll need to mount your Google Drive directory on your local file system:
$ drive init ~/gdrive $ cd ~/gdrive
The opposite of
drive init, it will remove your credentials locally as well as configuration associated files.
$ drive deinit [--no-prompt]
For a complete deinit-ialization, don't forget to revoke account access, please see revoking account access
pull command downloads data that does not exist locally but does remotely on Google drive, and may delete local data that is not present on Google Drive.
Run it without any arguments to pull all of the files from the current path:
$ drive pull
Pulling by matches is also supported
$ cd ~/myDrive/content/2015 $ drive pull --matches vines docx
To force download from paths that otherwise would be marked with no-changes
$ drive pull -force
To pull specific files or directories, pass in one or more paths:
$ drive pull photos/img001.png docs
Pulling by id is also supported
$ drive pull --id 0fM9rt0Yc9RTPaDdsNzg1dXVjM0E 0fM9rt0Yc9RTPaTVGc1pzODN1NjQ 0fM9rt0Yc9RTPV1NaNFp5WlV3dlU
Note: Checksum verification:
By default checksum-ing is turned off because it was deemed to be quite vigorous and unnecessary for most cases.
Due to popular demand to cover the common case in which size + modTime differences are sufficient to detect file changes. The discussion stemmed from issue #117.
To turn checksum verification back on:
$ drive pull -ignore-checksum=false
drive also supports piping pulled content to stdout which can be accomplished by:
$ drive pull -piped path1 path2
By default, the
pull command will export Google Docs documents as PDF files. To specify other formats, use the
$ drive pull -export pdf,rtf,docx,txt
To explicitly export instead of using
$ drive pull --export pdf,rtf,docx,txt --explicitly-export
By default, the exported files will be placed in a new directory suffixed by
\_exports in the same path. To export the files to a different directory, use the
$ drive pull -export pdf,rtf,docx,txt -export-dir ~/Desktop/exports
- doc, docx
- jpeg, jpg
- ppt, pptx
- txt, text
- xls, xlsx
push command uploads data to Google Drive to mirror data stored locally.
pull, you can run it without any arguments to push all of the files from the current path, or you can pass in one or more paths to push specific files or directories.
Note: To ignore checksum verification during a push:
$ drive push -ignore-checksum
drive also supports pushing content piped from stdin which can be accomplished by:
$ drive push -piped path
In relation to #107 and numerous other issues related to confusion about clashing paths, drive will abort on trying to deal with clashing names. To turn off this safety, pass in flag
In relation to #57 and @rakyll's #49. A couple of scenarios in which data was getting totally clobbered and unrecoverable, drive now tries to play it safe and warn you if your data could potentially be lost e.g during a to-disk clobber for which you have no backup. At least with a push you have the luxury of untrashing content. To disable this safety, run drive with flag
$ drive pull -ignore-conflict collaboration_documents
Playing the safety card even more, if you want to get changes that are non clobberable ie only additions run drive with flag
$ drive pull -no-clobber Makefile
Ordinarily your system will not traverse nested symlinks e.g:
$ mkdir -p a/b $ mkdir -p ~/Desktop/z1/z2 && ls ~ > ~/Desktop/z1/z2/listing.txt $ ln -s ~/Desktop/z1/z2 a/b $ ls -R a # Should print only z2 and nothing inside it.
However in relation to #80, for purposes of consistency with your Drive, traversing symlinks has been added.
For safety with non clobberable changes i.e only additions:
$ drive push -no-clobber
- Due to the reasons above, drive should be able to warn you in case of total clobbers on data. To turn off this behaviour/safety, pass in the
$ drive push -force sure_of_content
To pull without user input (i.e. without prompt)
$ drive push -quiet
$ drive push -no-prompt
To get Google Drive to convert a file to its native Google Docs format
$ drive push -convert
Extra features: to make Google Drive attempt Optical Character Recognition (OCR) for png, gif, pdf and jpg files.
$ drive push -ocr
Note: To use OCR, your account should have this feature. You can find out if your account has OCR allowed.
$ drive features
MimeType inference is from the file's extension.
If you would like to coerce a certain mimeType that you'd prefer to assert with Google Drive pushes, use flag
-coerce-mime <short-key>See List of MIME type short keys for the full list of short keys.
$ drive push -coerce-mime docx my_test_doc
- Excluding certain operations can be done both for pull and push by passing in flag
$ drive pull --exclude-ops "delete,update" vines $ drive push --exclude-ops "create" sensitive_files
- To show more information during pushes or pulls e.g show the current operation,
pass in option
$ drive pull --verbose 2015/Photos content $ drive push --verbose Music Fall2014
pub command publishes a file or directory globally so that anyone can view it on the web using the link returned.
$ drive pub photos
- Publishing by fileId is also supported
$ drive pub --id 0fM9rt0Yc9RTPV1NaNFp5WlV3dlU 0fM9rt0Yc9RTPSTZEanBsamZjUXM
unpub command is the opposite of
pub. It unpublishes a previously published file or directory.
$ drive unpub photos
- Publishing by fileId is also supported
$ drive unpub --id 0fM9rt0Yc9RTPV1NaNFp5WlV3dlU 0fM9rt0Yc9RTPSTZEanBsamZjUXM
Sharing and Emailing
share command enables you to share a set of files with specific users and assign them specific roles as well as specific generic access to the files. It also allows for email notifications on share.
$ drive share -emails firstname.lastname@example.org,email@example.com -message "This is the substring file I told you about" -role writer -type group mnt/substringfinder.c projects/kmp.c
For example to share a file with users of a mailing list and a custom message
$ drive share -emails firstname.lastname@example.org -message "Here is the drive code" -role group mnt/drive
- Also supports sharing by fileId
$ drive share --emails email@example.com --message "Developers, developers developers" --id 0fM9rt0Yc9RTPeHRfRHRRU0dIY97 0fM9rt0Yc9kJRPSTFNk9kSTVvb0U
unshare command revokes access of a specific accountType to a set of files.
$ drive unshare -type group mnt/drive
- Also supports unsharing by fileId
$ drive unshare --type group --id 0fM9rt0Yc9RTPeHRfRHRRU0dIY97 0fM9rt0Yc9kJRPSTFNk9kSTVvb0U
Files that exist remotely can be touched i.e their modification time updated to that on the remote server using the
$ drive touch Photos/img001.png logs/log9907.txt
For example to touch all files that begin with digits 0 to 9:
$ drive touch -matches $(seq 0 9)
- Also supports touching of files by fileId
$ drive touch --id 0fM9rt0Yc9RTPeHRfRHRRU0dIY97 0fM9rt0Yc9kJRPSTFNk9kSTVvb0U
Trashing and Untrashing
Files can be trashed using the
$ drive trash Demo
To trash files that contain a prefix match e.g all files that begin with Untitled, or Make
Note: This option uses the current working directory as the parent that the paths belong to.
$ drive trash -matches Untitled Make
Files that have been trashed can be restored using the
$ drive untrash Demo
To untrash files that match a certain prefix pattern
$ drive untrash -matches pQueue photos Untitled
- Also supports trashing/untrashing by fileId
$ drive trash --id 0fM9rt0Yc9RTPeHRfRHRRU0dIY97 0fM9rt0Yc9kJRPSTFNk9kSTVvb0U $ drive untrash --id 0fM9rt0Yc9RTPeHRfRHRRU0dIY97 0fM9rt0Yc9kJRPSTFNk9kSTVvb0U
Emptying the Trash
Emptying the trash will permanently delete all trashed files. Caution: They cannot be recovered after running this command.
$ drive emptytrash
Deleting items will PERMANENTLY remove the items from your drive. This operation is irreversible.
$ drive delete flux.mp4
$ drive delete --matches onyx swp
- Also supports deletion by fileIds
$ drive delete --id 0fM9rt0Yc9RTPeHRfRHRRU0dIY97 0fM9rt0Yc9kJRPSTFNk9kSTVvb0U
list command shows a paginated list of files present remotely.
Run it without arguments to list all files in the current directory's remote equivalent:
$ drive list
Pass in a directory path to list files in that directory:
$ drive list photos
To list matches
$ drive list --matches mp4 go
-trashed option can be specified to show trashed files in the listing:
$ drive list -trashed photos
To get detailed information about the listings e.g owner information and the version number of all listed files:
$ drive list -owners -l -version
- Also supports listing by fileIds
$ drive list -depth 3 --id 0fM9rt0Yc9RTPeHRfRHRRU0dIY97 0fM9rt0Yc9kJRPSTFNk9kSTVvb0U
- Listing allows for sorting by fields e.g
. To do this in reverse order, suffix_r
or-` to the selected key
e.g to first sort by modTime, then largest-to-smallest and finally most number of saves:
$ drive list --sort modtime,size_r,version_r Photos
- For advanced listing
$ drive list --skip-mime mp4,doc,txt $ drive list --match-mime xls,docx $ drive list --exact-title url_test,Photos
stat commands show detailed file information for example people with whom it is shared, their roles and accountTypes, and
fileId etc. It is useful to help determine whom and what you want to be set when performing share/unshare
$ drive stat mnt
stat won't recursively stat a directory, to enable recursive stating:
$ drive stat -r mnt
- Also supports stat-ing by fileIds
$ drive stat -r --id 0fM9rt0Yc9RTPeHRfRHRRU0dIY97 0fM9rt0Yc9kJRPSTFNk9kSTVvb0U
$ drive stat -depth 4 --id 0fM9rt0Yc9RTPeHRfRHRRU0dIY97 0fM9rt0Yc9kJRPSTFNk9kSTVvb0U
Retrieving md5 Checksums
md5sum command quickly retrieves the md5 checksums of the files on your drive. The result can be fed into the "md5sum -c" shell command to validate the integrity of the files on Drive versus the local copies.
Check that files on Drive are present and match local files:
~/MyDrive/folder$ drive md5sum | md5sum -c
Do a two-way diff (will also locate files missing on either side)
~/MyDrive/folder$ diff <(drive md5sum) <(md5sum *)
Same as above, but include subfolders
~/MyDrive/folder$ diff <(drive md5sum -r) <(find * -type f | sort | xargs md5sum)
Compare across two different Drive accounts, including subfolders
~$ diff <(drive md5sum -r MyDrive/folder) <(drive md5sum -r OtherDrive/otherfolder)
Note: Running the 'drive md5sum' command retrieves pre-computed md5 sums from Drive; its speed is proportional to the number of files on Drive. Running the shell 'md5sum' command on local files requires reading through the files; its speed is proportional to the size of the files.
drive allows you to create an empty file or folder remotely Sample usage:
$ drive new --folder flux $ drive new --mime-key doc bofx $ drive new --mime-key folder content $ drive new flux.txt oxen.pdf # Allow auto type resolution from the extension
quota command prints information about your drive, such as the account type, bytes used/free, and the total amount of storage available.
$ drive quota
features command provides information about the features present on the
drive being queried and the request limit in queries per second
$ drive features
about command provides information about the program as well as that about
your Google Drive. Think of it as a hybrid between the
$ drive about
OR for detailed information
$ drive about -features -quota
help command without any arguments to see information about the commands that are available:
$ drive help
Pass in the name of a command to get information about that specific command and the options that can be passed to it.
$ drive help push
To get help for all the commands
$ drive help all
drive allows you to copy content remotely without having to explicitly download and then reupload.
$ drive copy -r blobStore.py mnt flagging
$ drive copy blobStore.py blobStoreDuplicated.py
- Also supports copying by fileIds
$ drive copy -r --id 0fM9rt0Yc9RTPeHRfRHRRU0dIY97 0fM9rt0Yc9kJRPSTFNk9kSTVvb0U ../content
drive allows you to rename a file/folder remotely. To do so:
$ drive rename url_test url_test_results $ drive rename openSrc/2015 2015-Contributions
- Also supports renaming by fileId
$ drive rename 0fM9rt0Yc9RTPeHRfRHRRU0dIY97 fluxing
drive allows you to move content remotely between folders. To do so:
$ drive move photos/2015 angles library archives/storage
- Also supports moving by fileId
$ drive move --id 0fM9rt0Yc9RTPeHRfRHRRU0dIY97 0fM9rt0Yc9kJRPSTFNk9kSTVvb0U ../../new_location
drive allows you to specify a '.driveignore' file similar to your .gitignore, in the root directory of the mounted drive. Blank lines and those prefixed by '#' are considered as comments and skipped.
$ cat << $ >> .driveignore > # My drive ignore file > \.gd$ > \.so$ > \.swp$ > $
Note: Pattern matching and suffixes are done by regular expression matching so make sure to use a valid regular expression suffix.
As previously mentioned, Google Docs, Drawings, Presentations, Sheets etc and all files affiliated with docs.google.com cannot be downloaded raw but only exported. Due to popular demand, Linux users desire the ability to have *.desktop files that enable the file to be opened appropriately by an external opener. Thus by default on Linux, drive will create *.desktop files for files that fall into this category.
drive supports a few aliases to make usage familiar to the utilities in your shell e.g:
- cp : copy
- ls : list
- mv : move
- rm : delete
If you would like to fetch missing index files for files that would otherwise not need any modifications, run:
$ drive index path1 path2 path3/path3.1 # To fetch any missing indices in those paths $ drive index --id 0CLu4lbUI9RTRM80k8EMoe5JQY2z
You can also fetch specific files by prefix matches
$ drive index --matches mp3 jpg
In case you might have deleted files remotely but never using drive, and feel like you have stale indices,
drive index --prune will search your entire indices dir for index files that do not exist remotely and remove those ones
$ drive index --prune
- prune-and-index To combine both operations (prune and then fetch) for indices:
$ drive index --all-ops
The url command prints out the url of a file. It allows you to specify multiple paths relative to root or even by id
$ drive url Photos/2015/07/Releases intros/flux $ drive url --id 0Bz5qQkvRAeVEV0JtZl4zVUZFWWx 1Pwu8lzYc9RTPTEpwYjhRMnlSbDQ 0Cz5qUrvDBeX4RUFFbFZ5UXhKZm8
The open command allows for files to be opened by the default file browser, default web browser, either by path or by id for paths that exist atleast remotely
$ drive open --file-browser=false --web-browser f1/f2/f3 jamaican.mp4 $ drive open --file-browser --id 0Bz8qQkpZAeV9T1PObvs2Y3BMQEj 0Y9jtQkpXAeV9M1PObvs4Y3BNRFk
Revoking Account Access
To revoke OAuth Access of drive to your account, when logged in with your Google account, go to https://security.google.com/settings/security/permissions and revoke the desired permissions
drive from your computer, you'll need to take out:
- Also do not forget to revoke drive's access in case you need to uninstall it.
To apply patches of code e.g in the midst of bug fixes, you'll just need a little bit of git fiddling.
For example to patch your code with that on remote branch patch-1, you'll need to go into the source code directory, fetch all content from the git remote, checkout the patch branch then run the go installation: something like this.
$ cd $GOPATH/src/github.com/odeke-em/drive $ git fetch --all $ git checkout patch-1 $ git pull origin patch-1 $ go get github.com/odeke-em/drive/cmd/drive
Why another Google Drive client?
Background sync is not just hard, it is stupid. Here are my technical and philosophical rants about why it is not worth to implement:
Too racy. Data is shared between your remote resource, local disk and sometimes in your sync daemon's in-memory structs. Any party could touch a file at any time. It is hard to lock these actions. You end up working with multiple isolated copies of the same file and trying to determine which is the latest version that should be synced across different contexts.
It requires great scheduling to perform best with your existing environmental constraints. On the other hand, file attribute have an impact on the sync strategy. Large files block -- you wouldn't like to sit on and wait for a VM image to get synced before you can start working on a tiny text file.
It needs to read your mind to understand your priorities. Which file do you need most? It needs to read your mind to foresee your future actions. I'm editing a file, and saving the changes time to time. Why not to wait until I feel confident enough to commit the changes remotely?
drive is not a sync daemon, it provides:
Upstreaming and downstreaming. Unlike a sync command, we provide pull and push actions. The user has the opportunity to decide what to do with their local copy and when they decide to. Make some changes, either push the file remotely or revert it to the remote version. You can perform these actions with user prompt:
$ echo "hello" > hello.txt $ drive push # pushes hello.txt to Google Drive $ echo "more text" >> hello.txt $ drive pull # overwrites the local changes with the remote version
Allowing to work with a specific file or directory, optionally not recursively. If you recently uploaded a large VM image to Google Drive, yet only a few text files are required for you to work, simply only push/pull the exact files you'd like to worth with:
$ echo "hello" > hello.txt $ drive push hello.txt # pushes only the specified file $ drive pull path/to/a/b path2/to/c/d/e # pulls the remote directory recursively
Better I/O scheduling. One of the major goals is to provide better scheduling to improve upload/download times.
Possibility to support multiple accounts. Pull from or push to multiple Google Drive remotes. Possibility to support multiple backends. Why not to push to Dropbox or Box as well?
- It probably doesn't work on Windows.
- Google Drive allows a directory to contain files/directories with the same name. Client doesn't handle these cases yet. We don't recommend you to use
driveif you have such files/directories to avoid data loss.
- Racing conditions occur if remote is being modified while we're trying to update the file. Google Drive provides resource versioning with ETags, use Etags to avoid racy cases.
- drive rejects reading from namedPipes because they could infinitely hang. See issue #208.
Doing anything interesting with drive or want to share your favorite tips and tricks? Check out the wiki and feel free to reach out with ideas for features or requests.
This project is not supported nor maintained by Google.
Copyright 2013 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package contains the main entry point of gd.
|Package contains the main entry point of gd.|
Package bolt implements a low-level key/value store in pure Go.
|Package bolt implements a low-level key/value store in pure Go.|
Package drive provides access to the Drive API.
|Package drive provides access to the Drive API.|
Package isatty implements interface to isatty
|Package isatty implements interface to isatty|
Package command allows you to define subcommands for your command line interfaces.
|Package command allows you to define subcommands for your command line interfaces.|
Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes.
|Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes.|
Package oauth2 provides support for making OAuth2 authorized and authenticated HTTP requests.
|Package oauth2 provides support for making OAuth2 authorized and authenticated HTTP requests.|
Package clientcredentials implements the OAuth2.0 "client credentials" token flow, also known as the "two-legged OAuth 2.0".
|Package clientcredentials implements the OAuth2.0 "client credentials" token flow, also known as the "two-legged OAuth 2.0".|
Package facebook provides constants for using OAuth2 to access Facebook.
|Package facebook provides constants for using OAuth2 to access Facebook.|
Package github provides constants for using OAuth2 to access Github.
|Package github provides constants for using OAuth2 to access Github.|
Package google provides support for making OAuth2 authorized and authenticated HTTP requests to Google APIs.
|Package google provides support for making OAuth2 authorized and authenticated HTTP requests to Google APIs.|
Package jws provides encoding and decoding utilities for signed JWS messages.
|Package jws provides encoding and decoding utilities for signed JWS messages.|
Package jwt implements the OAuth 2.0 JSON Web Token flow, commonly known as "two-legged OAuth 2.0".
|Package jwt implements the OAuth 2.0 JSON Web Token flow, commonly known as "two-legged OAuth 2.0".|
Package linkedin provides constants for using OAuth2 to access LinkedIn.
|Package linkedin provides constants for using OAuth2 to access LinkedIn.|
Package odnoklassniki provides constants for using OAuth2 to access Odnoklassniki.
|Package odnoklassniki provides constants for using OAuth2 to access Odnoklassniki.|
Package paypal provides constants for using OAuth2 to access PayPal.
|Package paypal provides constants for using OAuth2 to access PayPal.|
Package vk provides constants for using OAuth2 to access VK.com.
|Package vk provides constants for using OAuth2 to access VK.com.|
Package googleapi contains the common code shared by all Google API libraries.
|Package googleapi contains the common code shared by all Google API libraries.|
Package transport contains HTTP transports used to make authenticated API requests.
|Package transport contains HTTP transports used to make authenticated API requests.|
Package metadata provides access to Google Compute Engine (GCE) metadata and API service accounts.
|Package metadata provides access to Google Compute Engine (GCE) metadata and API service accounts.|