Introduction

Rclone is a powerful command-line tool that supports synchronization, upload, and download of data between various object storage services and cloud drives. By configuring Rclone, you can achieve practical functions like offline downloading and server backups. In this guide, we’ll dive into commonly used Rclone commands and parameters to help you maximize its potential.

Installing Rclone

On Linux/macOS/BSD:

The official installation script can be executed with the following command:

curl https://rclone.org/install.sh | sudo bash

On Windows:

Simply download the executable from the official site.

Rclone Configuration

  • rclone config: This enters the interactive configuration menu where you can add, remove, and manage cloud storage accounts. For detailed steps, refer to the [Rclone Setup Guide].
  • rclone config file: Displays the path to the configuration file, typically located at ~/.config/rclone/rclone.conf.
  • rclone config show: Displays information from the configuration file.

Command Syntax

  • Local to Cloud:

    rclone [options] <local-path> <cloud-name:path> [parameters]
  • Cloud to Local:

    rclone [options] <cloud-name:path> <local-path> [parameters]
  • Cloud to Cloud:

    rclone [options] <cloud-name:path> <cloud-name:path> [parameters]

Usage Example

To move a file from your local /Download directory to OneDrive:

rclone move -v /Download Onedrive:/Download --transfers=1

Commonly Used Functions

  • rclone copy: Copy files from source to destination.
  • rclone move: Move files and delete the original. Use --delete-empty-src-dirs to remove empty source directories.
  • rclone sync: Synchronize directories, updating the target to match the source.
  • rclone size: Display the size of the cloud storage content.
  • rclone delete: Delete files within a specific path.
  • rclone purge: Delete the entire directory and its contents.
  • rclone mkdir: Create a new directory.
  • rclone rmdir: Remove an empty directory.
  • rclone rmdirs: Remove empty directories, with the --leave-root option to retain the root directory.
  • rclone check: Check if the data between the source and destination match.
  • rclone ls: List all files in a specific path, showing file sizes and paths.
  • rclone lsl: Same as ls, but also shows upload times.
  • rclone lsd: List directories in the specified path.
  • rclone lsf: List both files and directories in the specified path.

Common Parameters

  • -n, --dry-run: Preview actions without actually performing them.
  • -P, --progress: Show real-time transfer progress, refreshing every 500ms.
  • --cache-chunk-size: Set the size of chunks, default is 5MB. Larger sizes may improve upload speed but increase memory usage.
  • --transfers=N: Set the number of parallel file transfers (default is 4).
  • --ignore-errors: Skip errors during operations, useful for skipping problematic files like those flagged for malware in OneDrive.

Logging Levels

Rclone has four logging levels: ERROR, NOTICE, INFO, and DEBUG. By default, ERROR and NOTICE messages are logged.

  • -q: Only log ERROR messages.
  • -v: Log ERROR, NOTICE, and INFO messages (recommended).
  • -vv: Log ERROR, NOTICE, INFO, and DEBUG messages.
  • --log-level LEVEL: Set the logging level to the desired one.

Output Logs to File

Use --log-file=FILE to redirect logs to a specified file. You can also use system redirection like this:

rclone sync -v Onedrive:/DRIVEX Gdrive:/DRIVEX > "~/DRIVEX.log" 2>&1

File Filtering

  • --exclude: Exclude specific files or directories.
  • --include: Include specific files or directories.
  • --filter: More advanced filtering, combining include/exclude rules.

Example:

  • Exclude .bak files:

    --exclude "*.bak"
  • Include only png and jpg files:

    --include "*.{png,jpg}"

Directory Filtering

Add / after directory names for filtering. For example:

  • Exclude .git directories:

    --exclude ".git/"
  • Only include content within Video and Software directories:

    --include "/{Video,Software}/**"

File Size Filtering

Specify minimum and maximum file sizes for transfer:

  • Skip files smaller than 50KB:

    --min-size 50
  • Skip files larger than 1GB:

    --max-size 1G

Filter Rule Files

Use --filter-from <rules-file> to define filter rules in a file. Example file content:

- secret*.jpg
+ *.jpg
+ *.png
+ file2.avi
- /dir/Trash/**
+ /dir/**
- *

Environment Variables

Every Rclone option can be set using environment variables. The format is to convert the long option by removing the -- prefix, changing - to _, capitalizing it, and adding the RCLONE_ prefix.

Common Environment Variables:

  • RCLONE_CONFIG: Set a custom configuration file path.
  • RCLONE_RETRIES: Set the number of retry attempts (default is 3).
  • RCLONE_CACHE_CHUNK_SIZE: Set the size of cache chunks.
  • RCLONE_IGNORE_ERRORS=true: Skip errors during execution.

By mastering these commands and parameters, you can fully leverage Rclone's powerful capabilities for managing data across cloud storage platforms.

Last modification:October 3, 2024
如果觉得我的文章对你有用,请随意赞赏