'a bash script that remove duplicates
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
Solution 1:[1]
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
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | GravoLan |
| Solution 2 | Tyler2P |
