Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

Make dedupe take an optional mode parameter

Nick Craig-Wood38adb35abe25
diff --git a/docs/content/docs.md b/docs/content/docs.md
index 9c34981bf..641730989 100644
--- a/docs/content/docs.md
+++ b/docs/content/docs.md
@@ -283,6 +283,10 @@ For example to rename all the identically named photos in your Google Photos dir
rclone dedupe --dedupe-mode rename "drive:Google Photos"
+The modes can also be passed as an extra parameter, eg
+
+ rclone dedupe rename "drive:Google Photos"
+
### rclone config ###
Enter an interactive configuration session.
diff --git a/rclone.go b/rclone.go
index 07718f563..f1e4ede08 100644
--- a/rclone.go
+++ b/rclone.go
@@ -438,15 +438,32 @@ don't match. It doesn't alter the source or destination.`,
}
var dedupeCmd = &cobra.Command{
- Use: "dedupe remote:path",
+ Use: "dedupe [mode] remote:path",
Short: `Interactively find duplicate files delete/rename them.`,
Long: `
Interactively find duplicate files and offer to delete all
but one or rename them to be different. Only useful with
-Google Drive which can have duplicate file names.`,
+Google Drive which can have duplicate file names.
+
+Pass in an extra parameter to make the dedupe noninteractive
+
+ interactive - interactive as above.
+ skip - removes identical files then skips anything left.
+ first - removes identical files then keeps the first one.
+ newest - removes identical files then keeps the newest one.
+ oldest - removes identical files then keeps the oldest one.
+ rename - removes identical files then renames the rest to be different.
+`,
Run: func(cmd *cobra.Command, args []string) {
- checkArgs(1, 1, cmd, args)
- fdst := NewFsSrc(args[1])
+ checkArgs(1, 2, cmd, args)
+ if len(args) > 1 {
+ err := dedupeMode.Set(args[0])
+ if err != nil {
+ log.Fatal(err)
+ }
+ args = args[1:]
+ }
+ fdst := newFsSrc(args)
run(false, cmd, func() error {
return fs.Deduplicate(fdst, dedupeMode)
})