Original address: https://p3terx.com/archives/rclone-advanced-user-manual-common-command-parameters.html

Rclone is a command-line tool that supports synchronization, uploading, and downloading data between different object storage and network disks. And through some settings, very practical functions such as offline downloading and server backup can be realized. This article will explain some commonly used command parameters of Rclone.

Install Rclone

The official one-click installation script is provided:

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

Rclone settings

rclone config - 进入交互式配置选项,进行添加、删除、管理网盘等操作。
rclone config file - 显示配置文件的路径,一般配置文件在 ~/.config/rclone/rclone.conf,更换服务器可直接copy该文件。
rclone config show - 显示配置文件信息

Command syntax

# 本地到网盘
rclone [功能选项] <本地路径> <网盘名称:路径> [参数] [参数] ...
# 网盘到本地
rclone [功能选项] <网盘名称:路径> <本地路径> [参数] [参数] ...
# 网盘到网盘
rclone [功能选项] <网盘名称:路径> <网盘名称:路径> [参数] [参数] ...

Usage examples

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

Commonly used function options

rclone copy - 复制
rclone move - 移动,如果要在移动后删除空源目录,请加上 --delete-empty-src-dirs 参数
rclone sync - 同步:将源目录同步到目标目录,只更改目标目录。
rclone delete - 删除路径下的文件内容。
rclone purge - 删除路径及其所有文件内容。
rclone mkdir - 创建目录。
rclone rmdir - 删除目录。
rclone rmdirs - 删除指定灵境下的空目录。如果加上 --leave-root 参数,则不会删除根目录。
rclone check - 检查源和目的地址数据是否匹配。
rclone ls - 列出指定路径下的所有的文件以及文件大小和路径。
rclone lsl - 比上面多一个显示上传时间。
rclone lsd 列出指定路径下的目录
rclone lsf - 列出指定路径下的目录和文件

Commonly used parameters

-n = --dry-run - 测试运行,用来查看 rclone 在实际运行中会进行哪些操作。
-P = --progress - 显示实时传输进度。
--cache-chunk-size SizeSuffi - 块的大小,默认 5M,理论上是越大上传速度越快,同时占用内存也越多。如果设置得太大,可能会导致进程中断。
--cache-chunk-total-size SizeSuffix - 块可以在本地磁盘上占用的总大小,默认 10G。
--transfers=N - 并行文件数,默认为 4。在比较小的内存的 VPS 上建议调小这个参数,比如 128M 的小鸡上使用建议设置为 1。
--config string - 指定配置文件路径,string 为配置文件路径。比如在使用宝塔面板输入命令操作时可能会遇到找不到配置文件的问题,这时就需要指定配置文件路径。

log

rclone has 4 levels of logging, ERROR, NOTICE, INFO and DEBUG.

By default, rclone will generate ERROR and NOTICE level messages.

-q rclone 将仅生成 ERROR 消息。
-v rclone 将生成 ERROR,NOTICE 和 INFO 消息,推荐此项。
-vv rclone 将生成 ERROR,NOTICE,INFO 和 DEBUG 消息。
--log-level LEVEL 标志控制日志级别。

Output log to file

Using the --log-file=FILE option, rclone will redirect Error, Info, and Debug messages as well as standard error to FILE, where FILE is the log file path you specify.

Another method is to use the system's pointing command, such as:

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

File filtering

--exclude 排除文件或目录。比如 --exclude *.bak,排除所有 bak 文件。
--include 包含文件或目录。比如 --include *.{png,jpg} ,包含所有 png 和 jpg 文件,排除其他文件。
--delete-excluded 删除排除的文件。需配合过滤参数使用,否则无效。

Directory filtering

--exclude .git/ 排除所有目录下的 .git 目录。
--exclude /.git/ 只排除根目录下的 .git 目录。

Starting with / will only match the root directory, and if not, it will match all directories. The same applies to files.

File size filter

The default size unit is kBytes, but k , M or G suffixes can be used.

--min-size 过滤小于指定大小的文件。比如 --min-size 50 表示不会传输小于 50k 的文件。
--max-size 过滤大于指定大小的文件。比如 --max-size 1G 表示不会传输大于 1G 的文件。

File filtering rules

--filter-from <规则文件> 从文件添加包含 / 排除规则。比如 --filter-from filter-file.txt。

Example of filtering rule file:

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

+ means inclusion, - means exclusion

Here are only examples of some common and simple filtering usages. For more complex and advanced usages, you can check the official documentation.

Next, we need to mount the GoogleDrive network disk to the cloud host/VPS

Create a new directory you want to mount, for example, mount it to /home/gdrive

mkdir -p /home/gdrive

Then execute the mount command:

rclone mount gd: /home/gdrive --allow-other --allow-non-empty --vfs-cache-mode writes

gd is the configuration name of Rclone. For example, when you create and configure rclone, fill in the name gd, and /home/gdrive is the local path;

Here you can also customize the folder path in the network disk, for example:

rclone mount gd:backup /home/gdrive --allow-other --allow-non-empty --vfs-cache-mode writes

gd:backup gd is the configuration name of Rclone: ​​backup is the directory name in the network disk

It only takes a few seconds to mount, but the terminal will not return a success message. Just close SSH and reconnect. Ctrl+C cannot be used.

After reconnecting, check whether the mount is successful:

df -h

After seeing the gd hard disk, usage and local host path, it was successfully mounted.

gd: 15G  1.1M   15G   1% /home/gdrive

Unmount Google Drive

fusermount -qzu /home/gdrive


Leave a Reply