Gdrive (ver.2) Installation and Configuration
-
Download the Linux version of gdrive from GitHub.
12wget https://docs.google.com/uc?id=0B3X9GlR6EmbnWksyTEtCM0VfaFE&export=download -
You should see a file in your home directory called something list uc=0B3X9GlR6EmbnWksyTEtCM0VfaFE. Rename this file to gdrive.
12mv uc\?id\=0B3X9GlR6EmbnWksyTEtCM0VfaFE gdrive -
Assign this file executable rights.
12chmod +x gdrive -
Install the file to your usr folder.
12sudo install gdrive /usr/local/bin/gdrive -
connect to your google drive account
- from gdrive official site.
The first time gdrive is launched (i.e. run gdrive about in your terminal not just gdrive), you will be prompted for a verification code. The code is obtained by following the printed url and authenticating with the google account for the drive you want access to. This will create a token file inside the .gdrive folder in your home directory.
for multiple gdrive account:
If you want to manage multiple drives you can use the global –config{<i>php} flag or set the environment variable {php}GDRIVE_CONFIG_DIR. Example: GDRIVE_CONFIG_DIR=“/home/user</i>.gdrive-secondary“ gdrive list You will be prompted for a new verification code if the folder does not exist.
123gdrive list --config "/home/tan/.gdrive-mis" # orGDRIVE_CONFIG_DIR="/home/user/.gdrive-secondary" gdrive list
Usage
basic usage:
1 2 |
gdrive [global] command [options] <path> |
gdrive [global] list [options] | List files |
gdrive [global] download [options] <fileId> | Download file or directory |
gdrive [global] download query [options] <query> | Download all files and directories matching query |
gdrive [global] upload [options] <path> | Upload file or directory |
gdrive [global] upload – [options] <name> | Upload file from stdin |
gdrive [global] update [options] <fileId> <path> | Update file, this creates a new revision of the file |
gdrive [global] info [options] <fileId> | Show file info |
gdrive [global] mkdir [options] <name> | Create directory |
gdrive [global] share [options] <fileId> | Share file or directory |
gdrive [global] share list <fileId> | List files permissions |
gdrive [global] share revoke <fileId> <permissionId> | Revoke permission |
gdrive [global] delete [options] <fileId> | Delete file or directory |
gdrive [global] sync list [options] | List all syncable directories on drive |
gdrive [global] sync content [options] <fileId> | List content of syncable directory |
gdrive [global] sync download [options] <fileId> <path> | Sync drive directory to local directory |
gdrive [global] sync upload [options] <path> <fileId> | Sync local directory to drive |
gdrive [global] changes [options] | List file changes |
gdrive [global] revision list [options] <fileId> | List file revisions |
gdrive [global] revision download [options] <fileId> <revId> | Download revision |
gdrive [global] revision delete <fileId> <revId> | Delete file revision |
gdrive [global] import [options] <path> | Upload and convert file to a google document, |
gdrive [global] export [options] <fileId> | Export a google document |
gdrive [global] about [options] | Google drive metadata, quota usage |
gdrive [global] about import | Show supported import formats |
gdrive [global] about export | Show supported export formats |
gdrive version | Print application version |
gdrive help | Print help |
gdrive help <command> | Print command help |
gdrive help <command> <subcommand> | Print subcommand help |
Notes:
- see ’about import’ for available conversions | see ’about import’ for available conversions|
- operate on fileId, not file name, obtain from gdrive list
- upload download upload and download file or folders without converting
- import export convert to and from google docs in addtion to up/download.
- -mime to change tape
Some useful usages
-
Create directory
12gdrive [global] mkdir [options] <name> -
Show file info
12gdrive [global] info [options] <fileId> -
Share file or directory
123456789101112131415gdrive [global] share [options] <fileId>global:-c, --config <configDir> Application path, default: /Users/<user>/.gdrive--refresh-token <refreshToken> Oauth refresh token used to get access token (for advanced users)--access-token <accessToken> Oauth access token, only recommended for short-lived requests because of short lifetime (for advanced users)--service-account <accountFile> Oauth service account filename, used for server to server communication without user interaction (file is relative to config dir)options:--role <role> Share role: owner/writer/commenter/reader, default: reader--type <type> Share type: user/group/domain/anyone, default: anyone--email <email> The email address of the user or group to share the file with. Requires 'user' or 'group' as type--discoverable Make file discoverable by search engines--revoke Delete all sharing permissions (owner roles will be skipped)
Import and Export Files Between Google Drive and Emacs
Inspired from here.
upload or download file from emacs buffer to google drive
1 2 3 4 5 6 7 8 9 |
(defvar gdocs-folder-id "0B3kOusyMeFLVRXZ3QnpOb2x2eVE" "location for storing org to gdocs exported files, use 'gdrive list -t <foldername>' to find the id") (defun gdoc-upload-buffer-to-gdrive () "Export current buffer to gdrive folder identified by gdocs-folder-id" (interactive) (shell-command (format "gdrive upload --parent %s %s" gdocs-folder-id buffer-file-name))) |
import and export between emacs and google drive with conversion
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
(defun gdoc-download-to-current-buffer (doc) "This function is used to import a googleDoc file from a folder identified by gdocs-folder-id into current buffer." (interactive (list (completing-read "Choose one: " (split-string (shell-command-to-string (format "gdrive list -q \"'%s' in parents\"" gdocs-folder-id)) "\n")))) (setq my_shell_output (substring (shell-command-to-string ;;export and convert googel docs to text file (format "gdrive export --mime text/plain %s" (car (split-string doc " ")))) 0 -1)) (insert-file-contents (replace-regexp-in-string "\'" "" (nth 1 (split-string my_shell_output " "))))) |
How to mount google drive as a virtual file system
How To Mount Google Drive Locally As Virtual File System In Linux
1 2 3 4 |
rclone mount googledrive_tan: ~/gdrive_tan/ # Ctl+c umount fusermount -u ~/gdrive_tan |
OCT
About the Author:
Beyond 8 hours - Computer, Sports, Family...