dotfiles/.local/bin/scripts/duploc

25 lines
825 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 by locate.
# Args: [threshold (MB)] <filepaths...>
# OptDepends: synct (for checking against original filename)
2023-05-09 12:02:32 +00:00
while test $# -gt 0; do
case "$1" in
([0-9]|[0-9][0-9]) threshold=$1;;
(-n) noscan=$1;;
(-v) verbose=$1; set -x;;
(*) break;;
esac
shift
done
test "$noscan" || "Updating Locate Database..." && sudo updatedb
find "$@" -size +${threshold:-50}M -type f -exec sh -c "IFS=$'\n'; verbose='$verbose'"'
target="$(synct-unarchive "{}" || echo "{}")"
highlight "{}"
for existing in $(locate -b "$(basename "$target")")
do test "$verbose" && echo "Checking $existing against {}"
test -n "$(dupcheck "{}" "$existing")" &&
echo "Duplicate found at $existing" &&
rm -vi "{}" && break
2022-05-26 06:53:35 +00:00
done' \;