rclone Rmdir
rclone rmdir removes a single empty directory from a remote. If the directory contains any files, the command refuses to delete it — making it a safe cleanup tool.
Quick Summary
rmdir only removes empty directories. It's the safe counterpart to purge — you can never accidentally delete data with rmdir. Use rmdirs for recursive empty-directory cleanup.
Basic Syntax
rclone rmdir REMOTE:PATH
# Remove an empty directory
rclone rmdir remote:my-bucket/empty-folder
# Remove a local empty directory
rclone rmdir /var/backups/old-empty
If the directory is not empty, you'll see:
ERROR: Rmdir: directory not empty
Practical Examples
Clean Up After File Deletion
# Delete files first, then remove the empty dir
rclone delete remote:staging/old-data
rclone rmdir remote:staging/old-data
Remove a Test Directory
# Clean up after testing
rclone rmdir remote:test-bucket/scratch
Script with Safety Check
#!/bin/bash
# Only remove if directory is truly empty
if rclone ls remote:my-bucket/temp 2>&1 | grep -q .; then
echo "Directory not empty — skipping"
else
rclone rmdir remote:my-bucket/temp
echo "Removed empty directory"
fi
rmdir vs rmdirs vs purge
| Command | Scope | Requires Empty | Safe |
|---|---|---|---|
rmdir | Single directory | ✅ | ✅ |
rmdirs | Recursive (all empty dirs) | ✅ | ✅ |
purge | Recursive (everything) | ❌ | ❌ |
Common Pitfalls
| Pitfall | Consequence | Prevention |
|---|---|---|
Using rmdir on non-empty directory | Error — nothing happens (safe!) | Use delete first, then rmdir |
| Expecting recursive behavior | Only removes the specified directory | Use rmdirs for recursive cleanup |
What's Next
Examples with Output
1. Remove an empty remote folder
Delete a directory that no longer contains files. Command:
rclone rmdir gdrive:EmptyFolder
Output:
(No output on success)
2. Attempt to remove a non-empty folder
Observe the safety check when files still exist. Command:
rclone rmdir remote:ActiveFolder
Output:
2024/01/15 12:00:00 ERROR : directory not empty
3. Delete a local empty directory
Cleanup local workspace folders. Command:
rclone rmdir ./temp_local_dir
Output:
(Local directory removed if empty)
4. Dry run for directory removal
Verify which folder would be impacted. Command:
rclone rmdir remote:maybe_empty --dry-run -v
Output:
2024/01/15 12:00:00 NOTICE: maybe_empty: Not rmdir as --dry-run is set
5. Combine with list to see result
Confirm removal after execution. Command:
rclone rmdir remote:old && rclone lsd remote:old
Output:
2024/01/15 12:00:00 ERROR : directory not found