add simple deduper script
This commit is contained in:
parent
76162edb60
commit
30c9cf4ba3
1 changed files with 22 additions and 0 deletions
22
bash/dedupe.sh
Executable file
22
bash/dedupe.sh
Executable file
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -eo pipefail
|
||||
shopt -s globstar
|
||||
|
||||
if [[ -n "$1" ]]; then cd "$1"; fi
|
||||
|
||||
declare -A occurences
|
||||
|
||||
for file in **/*; do
|
||||
if [[ ! -f "$file" || -L "$file" ]]; then continue; fi
|
||||
hash=$(xxh128sum "$file" | cut -f1 -d' ')
|
||||
occurence=${occurences[$hash]}
|
||||
if [[ -n "$occurence" ]]; then
|
||||
relpath=$(realpath -s --relative-to "$(dirname "$file")" "$occurence")
|
||||
ln -sf "$relpath" "$file"
|
||||
echo "symlinked ${file@Q} to ${relpath@Q}" >&2
|
||||
else
|
||||
echo "first occurence of $hash: ${file@Q}" >&2
|
||||
occurences[$hash]=$file
|
||||
fi
|
||||
done
|
Loading…
Reference in a new issue