Code Monkey home page Code Monkey logo

dups's Introduction

Fork comment

This fork is designed to make it possible to install and use the dups cli direclty with

go install github.com/notPlancha/dups@latest
dups -h

I have not tested using it in a go project, I just wanted a neat tool. Enjoy the rest of the deps-cli.

dups

dups

dups is a CLI tool to find and remove duplicate files using different hash algorithms (MD5, SHA256 and XXHash) with multi-core support.

Install

Download binaries:

Release Page

To use in a go project:

go get github.com/notPlancha/dups

Usage

CLI

Available Commands:

Command Description
clean Finds duplicate files in a given path and deletes them.
scan Finds duplicate files in a given path but doesn't delete them.
help Help about any command

Flags:

flag Description
--algorithm string algorithm to use (md5/sha256/xxhash) (default "md5")
-f, --flat flat output, no extra info (only prints duplicate files)
-r, --full full search (search in sub-directories too)
--min-size int minimum file size to scan in bytes (default 10)
-s, --single-core use single cpu core

Examples:

Remove duplicates bigger than 1KB using multiple cpu cores:

dups clean path/to/directory --min-size 1024

Find duplicates and write them into file.txt:

dups scan path/to/directory -f >> file.txt

Find and list duplicates using single cpu core and XXHash algorithm:

dups scan path/to/directory -s --algorithm xxhash

Go code:

package main

import (
	"fmt"
	"github.com/notPlancha/dups"
)

func main()  {
	// list all files including files in any sub-directory
	files, err := dups.GetFiles("path/to/directory", true)
	if err != nil {
		panic(err)
	}

        // group files based on their file size
        fileGroups, totalFiles := dups.GroupFiles(files, 128)

	// collect hashes for groups with more than one file
	// singleThread: use a single thread
	// flatt: don't print the process bar or any other information
	hashes := dups.CollectHashes(fileGroups, false, dups.XXHash, false, totalFiles)
	duplicates, filesCount, duplicatesCount := dups.GetDuplicates(hashes)
	fmt.Println("total number of files with duplicates:", filesCount)
	fmt.Println("total number of duplicate files:", duplicatesCount)

	freedSize, deletedCount, err := dups.RemoveDuplicates(duplicates)
	if err != nil {
		panic(err)
	}
	fmt.Println("remove", deletedCount, "files")
	fmt.Println("freed a total of ", freedSize, "bytes")
}

Notes:

  • Use single core option (-s) if files are big (depending on your disk type).
  • Use XXHash algorithm for fast scanning and MD5/SHA256 for safest scanning or if the number of files is huge.

Build from source:

go build -tags multicore if you are building using Go < 1.5 or edit runtime.GOMAXPROCS() manually to support multi-core.

License

Apache

dups's People

Contributors

navid2zp avatar notplancha avatar nakayama900 avatar imgbotapp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.