Linux Upload to Google Drive with Command Line

Author

Reads 178

A Man Orange Knit Cap Uploading Files on a Laptop
Credit: pexels.com, A Man Orange Knit Cap Uploading Files on a Laptop

Uploading files to Google Drive from the Linux terminal can be a game-changer for productivity.

You can use the rclone command to upload files to Google Drive, which is a powerful tool for syncing files across different cloud storage services.

To use rclone, you'll need to install it on your Linux system, which can be done using the package manager.

The command to upload a file to Google Drive using rclone is quite straightforward, as you'll see in the next section.

Setup and Configuration

To set up and configure rclone for Google Drive, you'll need to create a remote called "remote" by running `rclone config`. This will guide you through an interactive setup process, including getting a token from Google Drive, which you'll need to do in your browser.

If you're running a host firewall, you may need to unblock the webserver that rclone runs on your local machine to collect the token. This webserver is accessible at http://127.0.0.1:53682/. You can then use rclone like this: `rclone mount remote: /mnt/google-drive`.

Credit: youtube.com, Using Rclone to sync files to Google Drive in GNU/Linux

You can also use a Service Account instead of OAuth2 token flow, which is useful for unattended mode. To do this, enter the path to your Service Account credentials at the `service_account_file` prompt during rclone config. Alternatively, you can set `service_account_credentials` with the actual contents of the file, or set the equivalent environment variable.

Setup and Configuration

To mount your Google Drive storage on your local machine, you'll want to use a tool like google-drive-ocamlfuse. This FUSE filesystem is written in OCaml and is available for free on GitHub.

It offers full read/write access, multiple account support, Unix permissions, and Team Drive support, making it a versatile option for managing your Google Drive storage.

If you're looking to configure your Google Drive setup, you may need to specify the account to impersonate using the --drive-impersonate option.

Here are some details about the --drive-impersonate option:

  • Config: impersonate
  • Env Var: RCLONE_DRIVE_IMPERSONATE
  • Type: string
  • Required: false

Install and Configure

To install and configure Google Drive, you'll need to choose between two popular options: google-drive-ocamlfuse and rclone. google-drive-ocamlfuse is a FUSE filesystem that lets users mount their Google Drive storage on the local machine, while rclone is a command-line program that syncs files and directories to and from Google Drive.

Credit: youtube.com, Install and Configure Ubuntu Server - Full Setup Guide

First, let's look at google-drive-ocamlfuse. To install it, simply run the command "sudo apt-get install google-drive-ocamlfuse" in your terminal. This will add the required package to your package manager's repository list and allow you to install it.

Once installed, create a mount point for Google Drive in your local filesystem by running "mkdir /mnt/google-drive". Then, mount the drive storage with the command "google-drive-ocamlfuse /mnt/google-drive". This will open your default browser and redirect you to the account authentication page for Google Drive.

To authenticate, select the account you want to mount locally and enter the password for the selected account. Next, Google will require permission to grant access to google-drive-ocamlfuse, so click on "Allow" and proceed to the next page. Once you allow permission, it will redirect you to the webpage of google-drive-ocamlfuse, where you can verify that the mounting process was successful.

Here are the steps to verify the mounting process:

1. Run the command "google-drive-ocamlfuse --mount"

2. Check the output to ensure that it displays a list of files and directories present in your Google Drive storage.

Alternatively, you can use rclone to configure Google Drive. To do this, run the command "rclone config" to guide you through an interactive setup process. You'll need to enter the path to your Service Account credentials at the service_account_file prompt, or set service_account_credentials with the actual contents of the file instead.

Note that rclone runs a webserver on your local machine to collect the token as returned from Google if using web browser to automatically authenticate. This only runs from the moment it opens your browser to the moment you get back the verification code.

You might enjoy: Linux Google Drive Mount

Root Folder ID

Credit: youtube.com, NodeJS : Google DRIVE API V3 - Get a root folder ID with nodejs

The root folder ID is a crucial setting in rclone that determines the starting point for your drive. You can find the root folder ID by opening the relevant folder in the drive web interface and looking at the last segment of the URL.

In most cases, you'll leave this blank and rclone will determine the correct root to use itself. However, you can set the root folder ID to restrict rclone to a specific folder hierarchy or to access data within the "Computers" tab on the drive web interface.

To access "Computers" folders, you'll need to fill in the root folder ID with the last segment of the URL when you open the relevant folder in the drive web interface. This will allow rclone to use a non-root folder as its starting point.

You can set the root folder ID in the config file or as an environment variable. The config option is called "root_folder_id" and the environment variable is called "RCLONE_DRIVE_ROOT_FOLDER_ID". Both are strings and are not required.

Here's a summary of the options:

Note that folders under the "Computers" tab seem to be read-only when using rclone, giving a 500 error.

Allow Import Name

Black Samsung Tablet Display Google Browser on Screen
Credit: pexels.com, Black Samsung Tablet Display Google Browser on Screen

Allow Import Name is a crucial setting that determines how rclone handles file name changes during sync operations. It's essential to understand this setting to ensure seamless file transfers.

The allow_import_name_change option allows you to enable or disable the import of file name changes. By default, this option is set to false.

To configure this setting, you can use the allow_import_name_change config option or the RCLONE_DRIVE_ALLOW_IMPORT_NAME_CHANGE environment variable. Both methods allow you to set this option to true or false.

Here's a summary of the available options:

  • Config: allow_import_name_change
  • Env Var: RCLONE_DRIVE_ALLOW_IMPORT_NAME_CHANGE
  • Type: bool
  • Default: false

This setting is particularly useful when you need to rename files with a different extension, such as changing a file from .doc to .docx. However, be aware that enabling this setting can cause sync issues if not managed properly.

Quota Information

To view your current quota, simply use the rclone about remote command. This command will display your usage limit (quota), the usage in Google Drive, and the space used by other Google services such as Gmail.

Credit: youtube.com, Implementing Linux Quotas

The rclone about remote command is a quick and easy way to get an overview of your quota information without needing to navigate through multiple settings.

You can run this command without any path arguments, making it a convenient option for checking your quota on the fly.

The command will also display the size of all files in the Trash, giving you a clear picture of your storage usage.

Server Side Across Configs

Server Side Across Configs is a feature that allows server-side operations to work across different drive configurations. This can be useful if you need to perform a server-side copy between two different Google drives.

By default, this feature isn't enabled because it's tricky to determine if it will work between any two configurations. However, you can enable it if you need to.

Here are the details of the Server Side Across Configs feature:

  • Config: server_side_across_configs
  • Env Var: RCLONE_DRIVE_SERVER_SIDE_ACROSS_CONFIGS
  • Type: bool
  • Default: false

Note that the feature has been deprecated in favor of a new option, --server-side-across-configs.

Skip

A Black Android Smartphone with Google Apps on Screen
Credit: pexels.com, A Black Android Smartphone with Google Apps on Screen

I've come across a useful feature in rclone that allows you to skip Google Docs when syncing files.

You can configure rclone to skip Google Docs by setting the `skip_gdocs` option to `true`. This is done by adding the `--drive-skip-gdocs` flag when running rclone.

Here's how you can do it:

  • Config: `skip_gdocs`
  • Env Var: `RCLONE_DRIVE_SKIP_GDOCS`
  • Type: `bool`
  • Default: `false`

By setting `skip_gdocs` to `true`, you can speed up your syncing process and avoid dealing with Google Docs files. Just remember to set it to `false` if you need to sync Google Docs files.

Additional reading: Google Drive to Docs

Show All

When working with Google Drive, you might encounter issues with server-side copying of Google Forms. This is where the "show all" flag comes in handy. Adding the "--drive-show-all-gdocs" flag will allow server-side copying of Google Forms to work as expected.

This flag is particularly useful when trying to copy a Google Form, as it will prevent errors from occurring. Simply include the flag in your rclone command to enable this feature.

Person in winter gear using a laptop with a Google search on screen outdoors.
Credit: pexels.com, Person in winter gear using a laptop with a Google search on screen outdoors.

The "--drive-show-all-gdocs" flag is a boolean option, meaning it can only be set to true or false. The default setting is false, but you can change this in your rclone configuration or by setting the RCLONE_DRIVE_SHOW_ALL_GDOCS environment variable.

Here's a quick rundown of the details:

  • Config: show_all_gdocs
  • Env Var: RCLONE_DRIVE_SHOW_ALL_GDOCS
  • Type: bool
  • Default: false

It's worth noting that this flag should not be used when trying to download Google Docs, as rclone will fail in this case.

Jennie Bechtelar

Senior Writer

Jennie Bechtelar is a seasoned writer with a passion for crafting informative and engaging content. With a keen eye for detail and a knack for distilling complex concepts into accessible language, Jennie has established herself as a go-to expert in the fields of important and industry-specific topics. Her writing portfolio showcases a depth of knowledge and expertise in standards and best practices, with a focus on helping readers navigate the intricacies of their chosen fields.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.