dotfiles/.local/bin/scripts/duploc

12 lines
682 B
Bash
Executable File

#!/bin/sh
# Delete files under current or given path which exist elsewhere as listed in the locate database
# Matches first by name, then by checksum (currently inefficiently via md5)
case $1 in ([0-9]|[0-9][0-9]) threshold=$1; shift;; esac
find "$@" -size +${threshold:-50}M -type f -exec sh -c "IFS=$'\n'"'
filepath="{}"
target="$(synct-unarchive "$filepath")"
highlight "$filepath"
for existing in $(locate -b "$target")
do test "$(realpath "$target")" != "$(realpath "$existing")" -a -f "$existing" && test "$(md5sum "$existing" | cut -d\ -f1)" = "$(md5sum "$filepath" | cut -d\ -f1)" && echo "Found duplicate at $existing" && rm -vi "$filepath" && break
done' \;