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.
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
| Flag | Description |
|---|---|
--dry-run / -n | Preview deletions without executing |
--verbose / -v | Show files being deleted |
--include PATTERN | Delete only files matching pattern |
--exclude PATTERN | Protect files matching pattern |
--min-age DURATION | Only delete files older than DURATION |
--max-age DURATION | Only delete files newer than DURATION |
--min-size SIZE | Only delete files larger than SIZE |
--rmdirs | Also remove empty directories after deleting files |
--log-file PATH | Write 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
#!/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
| Command | Deletes Files | Deletes Directories | Use Case |
|---|---|---|---|
delete | ✅ | Only with --rmdirs | Selective file cleanup |
purge | ✅ | ✅ (everything) | Complete path removal |
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
| Pitfall | Consequence | Prevention |
|---|---|---|
Running without --dry-run | Permanent data loss | Always preview first |
No --include filter | Deletes ALL files in the path | Use filters to target specific files |
Forgetting --rmdirs | Empty directories accumulate | Add --rmdirs or run rclone rmdirs after |
| Backend without trash | No recovery possible | Check 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)