This works wrong script should delete only copies, but this script deletes all files
#!/bin/bash
DIR=$1
if [[ -z "$DIR" ]]; then
echo "Error: files dir is undefined"
fi
files="$( find ${DIR} -type f )"
for file1 in $files; do
for file2 in $files; do
if cmp -s "$file1" "$file2"; then
rm $file2
fi
done
done
CodePudding user response:
Found this on superuser:
#!/bin/bash
declare -A arr
shopt -s globstar
for file in **; do
[[ -f "$file" ]] || continue
read cksm _ < <(md5sum "$file")
if ((arr[$cksm] )); then
echo "rm $file"
fi
done
CodePudding user response:
I find answer:
#!/bin/bash
DIR=$1
if [[ -z "$DIR" ]]; then
echo "Error: files dir is undefined"
fi
files="$( find ${DIR} -type f )"
for file1 in $files; do
for file2 in $files; do
if cmp -s "$file1" "$file2"; then
rm $file2
fi
done
done