Skip to main content

rclone Delete

rclone delete removes files from the given path. It deletes files only — empty directories are left behind. Use this for selective cleanup without destroying the folder structure.

Destructive Command

Deleted files cannot be recovered (unless the backend has a trash/recycle bin feature). Always preview with --dry-run first.

Basic Syntax

rclone delete REMOTE:PATH [flags]
# Delete all files under a path (keeps empty dirs)
rclone delete remote:my-bucket/temp-data

# Delete specific file types
rclone delete remote:my-bucket/logs --include "*.log"

# Dry run — preview what would be deleted
rclone delete remote:my-bucket/temp-data --dry-run -v

Key Flags

FlagDescription
--dry-run / -nPreview deletions without executing
--verbose / -vShow files being deleted
--include PATTERNDelete only files matching pattern
--exclude PATTERNProtect files matching pattern
--min-age DURATIONOnly delete files older than DURATION
--max-age DURATIONOnly delete files newer than DURATION
--min-size SIZEOnly delete files larger than SIZE
--rmdirsAlso remove empty directories after deleting files
--log-file PATHWrite deletion log

Practical Examples

Delete Old Log Files

# Remove log files older than 90 days
rclone delete remote:logs --min-age 90d --include "*.log" -v

Clean Up Temporary Files

# Remove temp files from a bucket
rclone delete remote:my-bucket --include "*.tmp" --include "*.bak" -v

Delete Files and Empty Directories

# Remove everything and clean up empty dirs
rclone delete remote:my-bucket/staging --rmdirs -v

Delete with Protection Pattern

# Delete everything EXCEPT database dumps
rclone delete remote:backups/old \
--exclude "*.sql.gz" --dry-run -v

Automated Cleanup Script

cleanup.sh
#!/bin/bash
LOG="/var/log/rclone/cleanup-$(date +%Y-%m-%d).log"

# Delete files older than 30 days from temp storage
rclone delete remote:temp-storage \
--min-age 30d \
--log-file "$LOG" --log-level INFO -v

# Clean up empty directories
rclone rmdirs remote:temp-storage --log-file "$LOG"

delete vs purge

CommandDeletes FilesDeletes DirectoriesUse Case
deleteOnly with --rmdirsSelective file cleanup
purge✅ (everything)Complete path removal
tip

Use delete when you want to clean up specific files while keeping the directory structure. Use purge when you want to nuke an entire path.

Common Pitfalls

PitfallConsequencePrevention
Running without --dry-runPermanent data lossAlways preview first
No --include filterDeletes ALL files in the pathUse filters to target specific files
Forgetting --rmdirsEmpty directories accumulateAdd --rmdirs or run rclone rmdirs after
Backend without trashNo recovery possibleCheck if backend supports trash before deleting

What's Next

Examples with Output

1. Delete all logs older than 30 days

Clean up specific files while keeping the folder structure. Command:

rclone delete remote:backups/logs --min-age 30d

Output:

(No output on success unless -v is used)

2. Dry run of file deletion

Safely preview which files would be removed. Command:

rclone delete remote:temp --dry-run -v

Output:

2024/01/15 12:00:00 NOTICE: old_tmp.bak: Not deleting as --dry-run is set
2024/01/15 12:00:00 NOTICE:
Deleted: 1

3. Delete specific file type recursively

Remove all .tmp files across all subdirectories. Command:

rclone delete remote:project --include "*.tmp"

Output:

(Scanning subfolders and deleting all matching files)

4. Delete and clean up empty directories

Remove files and the folders that housed them. Command:

rclone delete remote:expendable_data --rmdirs

Output:

(Files deleted, then empty directories removed)

5. Log the cleanup process

Maintain an audit trail of deleted files. Command:

rclone delete remote:cleanup_job --log-file rclone-delete.log --log-level INFO

Output:

(Detailed log entries written to rclone-delete.log)