View on GitHub

hashdir

A command-line utility to checksum directories and files.

Overview

sample terminal usage

hashdir is a simple command-line tool to hash directories and files.

A hash or checksum is a short sequence of letters and numbers derived from another (often larger) sequence of data. Checksums are created from input data using a hashing algorithm. For a good hashing algorithm, it is extremely difficult to come up with an input that results in a specific checksum. Therefore a checksum acts like a digital fingerprint - if the checksums match we can be reasonably sure the input data matches.

This is useful in many situations:

Installation

There are several ways to install hashdir, and they are listed below roughly in order of convenience. You can choose the method that fits your needs. The latest release can always be found at https://github.com/ultimateanu/hashdir/releases.

Stand-alone binary

This is a single executable file with no external dependencies. It is available for various operating systems (e.g. macOS, Windows, Linux). This method is very simple but the stand-alone binaries are quite large since they bundle in the necessary dotnet runtime.

  1. Download the latest version for your OS from releases
  2. Extract the contents of the .zip or .tar.gz file
  3. Run the binary
    ./hashdir --help
    
  4. Optional: copy the executable to a directory in your PATH (e.g. /usr/local/bin)

Package manager

hashdir is available via package managers. If you already have a package manager, this allows for easy installation and upgrades.

*Homebrew currently requires a project to have 50 stars to be included in core. So I’ve set up a custom tap for now that still allows easy installation. If you like this project, please consider starring on Github and adding a formula to Homebrew core eventually.

Cross-platform dotnet app

If you already have the dotnet runtime on your machine, you can use the dotnet application which is a cross-platform solution. Since this relies on the dotnet platform for your system, the resulting size is significantly smaller.

  1. Download the hashdir_x.y.z_dotnet zip or tar.gz file from releases
  2. Extract the contents of the .zip or .tar.gz file
  3. Run the app
    dotnet hashdir.dll --help
    

Build from source

Since this is an open-source project you can also build from source! This requires dotnet 7.

  1. Download the source code from the main branch on GitHub
  2. Optional: Build and run the app
    dotnet run --project src/App/App.fsproj -- --help
    
  3. Publish a release version
    dotnet publish -c Release src/App/App.fsproj
    
  4. Run the app
    dotnet src/App/bin/Release/net7.0/publish/hashdir.dll --help
    

Usage

Description:
  A command-line utility to hash directories and files.

Usage:
  hashdir [<item>...] [command] [options]

Arguments:
  <item>  Directory or file to hash/check

Options:
  -t, --tree                                                 Print directory tree
  -s, --save                                                 Save the checksum to a file
  -a, --algorithm <md5|ripemd160|sha1|sha256|sha384|sha512>  The hash function to use [default: sha1]
  -i, --include-hidden-files                                 Include hidden files
  -e, --skip-empty-dir                                       Skip empty directories
  -n, --ignore <pattern>                                     Directories/files to not include
  -h, --hash-only                                            Print only the hash
  -c, --color                                                Colorize the output [default: True]
  --version                                                  Show version information
  -?, -h, --help                                             Show help and usage information


Commands:
  check <item>  Verify that the specified hash file is valid.

Examples

  1. Get the checksum of a file or directory.
    hashdir ~/Desktop/project/
    
  2. Get the checksum of a directory with the hidden files. Print out all subdirectories and files (tree).
    hashdir --include-hidden-files --tree ~/Desktop/project
    
  3. Get the MD5 checksum of multiple items.
    hashdir -a md5 song.mp3 info.txt report.pdf
    
  4. Hash a directory, but ignore certain directories/files.
    hashdir --ignore "node_modules" --ignore "**/*.xml" ~/Desktop/project
    

About

hashdir is an open-source project with a permissive MIT License. If you find a bug or have suggestions feel free to create an issue on Github. Any contributions to the code, tests, or documentation are also welcome via a pull request.