Skip to content

Instantly share code, notes, and snippets.

@randria
Created July 18, 2023 05:36
Show Gist options
  • Save randria/df5d7cad21ff9d8574bc1a8cfc5cb998 to your computer and use it in GitHub Desktop.
Save randria/df5d7cad21ff9d8574bc1a8cfc5cb998 to your computer and use it in GitHub Desktop.
hash photo files and move to another file removing duplicates
#!/bin/bash
do_hash(){
[ -f shasum.txt ] && mv -fv shasum.txt shasum_$(date +%s).txt
shasum -a 256 * | tee -a shasum.txt && \
awk '{print $1}' shasum.txt | sort | uniq > shasum_hash.txt
}
do_move(){
[ -z "$1" -o $# -eq 0 ] && return 1
SRC=$(pwd); DST=$1;
comm -23 ${SRC}/shasum_hash.txt ${DST}/shasum_hash.txt | while read hash; do FILE=$(grep ^$hash ${SRC}/shasum.txt | awk '{print $2}'|head -1); [ ! -f ${SRC}/$FILE ] && continue; mv -v ${SRC}/$FILE ${DST}/new-$(echo $hash | head -c12).${FILE#*.} && sed -I_bak "/^$hash/d" ${SRC}/shasum.txt; done
}
$*
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment