Last active
March 14, 2022 08:45
-
-
Save frafra/59a276250c57cedac454d43dafe80347 to your computer and use it in GitHub Desktop.
Find identical files and folders (comparing file names, paths and sizes)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Example: | |
# $ ./find-dupes-dir.sh $HOME/Documents/*/ | |
set -Eeuo pipefail | |
declare -A dirs | |
for dir in "$@" | |
do | |
cd "$dir" | |
checksum="$(find . -printf '%p %b\n' | sort | shasum - | cut -f1 -d' ')" | |
if [[ -z "${dirs[$checksum]-}" ]] | |
then | |
dirs[$checksum]="$dir" | |
else | |
>&2 echo "$dir is a duplicate of ${dirs[$checksum]}" | |
echo "$dir" | |
fi | |
cd "$OLDPWD" | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Example: | |
# $ fd -e jpg . $HOME/Pictures | ./find-dupes.sh | |
set -Eeuo pipefail | |
declare -A paths | |
while read path | |
do | |
filename="${path##*/}" | |
identifier="$filename/$(stat --printf='%s' "$path")" | |
if [[ -z "${paths[$identifier]-}" ]] | |
then | |
paths[$identifier]="$path" | |
else | |
>&2 echo "$path is a duplicate of ${paths[$identifier]}" | |
echo "$path" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The output (stdout) can be stored to a file or just piped into
xargs -d$'\n' rm
for immediate removal.