How to use the command 'gdrive' (with examples)
The ‘gdrive’ command is a command-line tool that allows users to interact with Google Drive. It can be used to upload files or folders to Google Drive, download files or directories from Google Drive, and create new revisions of files or folders on Google Drive. It provides a convenient way to manage and transfer files between a local machine and Google Drive.
Use case 1: Upload a local path to the parent folder with the specified ID
Code:
gdrive upload -p <id> <path/to/file_or_folder>
Motivation: Uploading files or folders to Google Drive is a common task, and this use case provides a simple and efficient way to do so. By specifying the ID of the parent folder, the uploaded file or folder will be placed in the desired location within Google Drive.
Explanation:
upload
: The ‘upload’ subcommand specifies that we want to upload a file or folder to Google Drive.-p <id>
: The ‘-p’ option is used to specify the parent folder ID where the file or folder should be uploaded.<path/to/file_or_folder>
: This is the path of the local file or folder that should be uploaded.
Example output:
$ gdrive upload -p 123abc path/to/file.txt
Uploading path/to/file.txt
Uploaded 123abc/file.txt
Use case 2: Download file or directory by ID to current directory
Code:
gdrive download <id>
Motivation: Downloading files or directories from Google Drive to the local machine is another common task. This use case allows users to easily specify the ID of the file or directory they want to download and automatically saves it to the current directory.
Explanation:
download
: The ‘download’ subcommand specifies that we want to download a file or directory from Google Drive.<id>
: This is the ID of the file or directory that should be downloaded.
Example output:
$ gdrive download 123abc
Downloading 123abc/file.txt
Downloaded file.txt
Use case 3: Download to a given local path by its ID
Code:
gdrive download --path <path/to/folder> <id>
Motivation: Sometimes, users may want to download files or directories from Google Drive to a specific local path instead of the current directory. This use case allows users to specify the desired local path and ensures that the downloaded file or directory is saved to the correct location.
Explanation:
download
: The ‘download’ subcommand specifies that we want to download a file or directory from Google Drive.--path <path/to/folder>
: This option is used to specify the local path where the file or directory should be downloaded.<id>
: This is the ID of the file or directory that should be downloaded.
Example output:
$ gdrive download --path /path/to/download/folder 123abc
Downloading 123abc/file.txt
Downloaded /path/to/download/folder/file.txt
Use case 4: Create a new revision of an ID using a given file or folder
Code:
gdrive update <id> <path/to/file_or_folder>
Motivation: When working with files or folders on Google Drive, it is often necessary to update them with new revisions. This use case allows users to create a new revision of a file or folder on Google Drive by providing the ID of the existing file or folder and the path to the new file or folder.
Explanation:
update
: The ‘update’ subcommand specifies that we want to create a new revision of a file or folder on Google Drive.<id>
: This is the ID of the existing file or folder that should be updated.<path/to/file_or_folder>
: This is the path of the new file or folder that should be used to create the new revision.
Example output:
$ gdrive update 123abc path/to/new/file.txt
Updating 123abc
Updated 123abc/new_file.txt
Conclusion:
The ‘gdrive’ command is a versatile tool for managing and transferring files between a local machine and Google Drive. It provides a simple and efficient way to upload files or folders to Google Drive, download files or directories from Google Drive, and create new revisions of files or folders on Google Drive. By understanding and utilizing the various use cases of the ‘gdrive’ command, users can streamline their workflows and make the most out of their Google Drive integration.