rclone 命令

基础查看命令

1. 列出文件和目录

bash

# 列出根目录内容
rclone ls aliyun-drive:

# 列出特定目录内容
rclone ls aliyun-drive:/path/to/directory

# 以树形结构显示(带大小)
rclone lsl aliyun-drive:

# 只显示目录结构(不显示文件大小)
rclone lsd aliyun-drive:

# 递归显示所有文件(类似 ls -la)
rclone lsf aliyun-drive: --format "tsp"

2. 树形查看

bash

# 显示目录树结构
rclone tree aliyun-drive:

# 限制显示深度
rclone tree aliyun-drive: --level 2

# 显示文件大小
rclone tree aliyun-drive: --size

详细信息命令

3. 获取文件详细信息

bash

# 显示文件/目录的详细信息
rclone lsjson aliyun-drive:/path

# 格式化输出详细信息
rclone lsjson aliyun-drive: --format json | python -m json.tool

# 显示包含元数据的信息
rclone lsjson aliyun-drive: -M

4. 统计信息

bash

# 显示存储空间使用情况
rclone about aliyun-drive:

# 统计文件数量和总大小
rclone size aliyun-drive:

# 检查特定路径
rclone size aliyun-drive:/Movies

高级查看命令

5. 搜索文件

bash

# 按文件名搜索
rclone lsf aliyun-drive: --include "*.mp4"

# 搜索包含特定关键词的文件
rclone lsf aliyun-drive: --include "*movie*"

# 排除某些文件类型
rclone lsf aliyun-drive: --exclude "*.tmp"

6. 实时监控

bash

# 实时查看某个目录的变化(需要支持的云盘)
rclone lsjson aliyun-drive: --poll-interval 10s

针对你的 OpenList 场景

假设你的 rclone 配置名为 aliyun-drive,以下是实用示例:

bash

# 查看阿里云盘根目录
rclone ls aliyun-drive:

# 查看视频文件目录
rclone lsl aliyun-drive:/电影
rclone lsl aliyun-drive:/电视剧

# 搜索所有视频文件
rclone lsf aliyun-drive: --include "*.{mp4,mkv,avi,mov}" -R

# 查看目录树结构
rclone tree aliyun-drive: --level 3

# 获取存储空间信息
rclone about aliyun-drive:

# 统计视频文件总大小
rclone size aliyun-drive:/电影

格式化输出

7. 自定义输出格式

bash

# 自定义显示格式:时间、大小、路径
rclone lsf aliyun-drive: --format "tsp" -R

# 只显示文件名
rclone lsf aliyun-drive: --format "p"

# 显示修改时间和文件名
rclone lsf aliyun-drive: --format "tp"

实用脚本示例

创建一个 Python 脚本来更方便地查看内容:

python

#!/usr/bin/env python3
import subprocess
import json
import sys

def run_rclone_command(cmd):
    """执行 rclone 命令并返回结果"""
    try:
        result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
        if result.returncode == 0:
            return result.stdout.strip()
        else:
            print(f"错误: {result.stderr}")
            return None
    except Exception as e:
        print(f"执行命令失败: {e}")
        return None

def show_directory_tree(aliyun_drive, path="", level=2):
    """显示目录树"""
    cmd = f"rclone tree {aliyun_drive}:{path} --level {level}"
    result = run_rclone_command(cmd)
    if result:
        print(result)

def search_videos(aliyun_drive, path=""):
    """搜索视频文件"""
    cmd = f"rclone lsf {aliyun_drive}:{path} --include '*.{{mp4,mkv,avi,mov,rmvb,flv}}' -R"
    result = run_rclone_command(cmd)
    if result:
        print("找到的视频文件:")
        for line in result.split('\n'):
            if line:
                print(f"  {line}")

def get_storage_info(aliyun_drive):
    """获取存储信息"""
    cmd = f"rclone about {aliyun_drive}"
    result = run_rclone_command(cmd)
    if result:
        print("存储空间信息:")
        print(result)

if __name__ == "__main__":
    aliyun_drive = "aliyun-drive"  # 你的 rclone 配置名
    
    if len(sys.argv) > 1:
        if sys.argv[1] == "tree":
            show_directory_tree(aliyun_drive)
        elif sys.argv[1] == "videos":
            search_videos(aliyun_drive)
        elif sys.argv[1] == "info":
            get_storage_info(aliyun_drive)
    else:
        print("使用方法:")
        print("python script.py tree   - 显示目录树")
        print("python script.py videos - 搜索视频文件") 
        print("python script.py info   - 显示存储信息")

快捷别名设置

~/.bashrc 中添加一些快捷别名:

bash

# rclone 快捷命令
alias rls='rclone ls aliyun-drive:'
alias rtree='rclone tree aliyun-drive:'
alias rsize='rclone size aliyun-drive:'
alias rabout='rclone about aliyun-drive:'
alias rvideo='rclone lsf aliyun-drive: --include "*.{mp4,mkv,avi,mov}" -R'