dotfiles/.local/bin/scripts/duploc

12 lines
682 B
Plaintext
Raw Normal View History

2022-10-24 20:22:45 +00:00
#!/bin/sh
# Delete files under current or given path which exist elsewhere as listed in the locate database
2022-05-19 20:24:44 +00:00
# Matches first by name, then by checksum (currently inefficiently via md5)
2022-06-27 09:24:06 +00:00
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'"'
2022-05-26 06:53:35 +00:00
filepath="{}"
2022-10-24 20:22:45 +00:00
target="$(synct-unarchive "$filepath")"
highlight "$filepath"
2022-05-26 06:53:35 +00:00
for existing in $(locate -b "$target")
2022-06-27 09:24:06 +00:00
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
2022-05-26 06:53:35 +00:00
done' \;