Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #this script will search for duplicate files
- #if it finds duplicates it will write the path of the file
- #and its duplicates for later manual operations
- #
- cd "your/files/directory"
- outputDir="${HOME}/testDups"
- files=$( find "$PWD" -type f 2>/dev/null )
- i=1
- while true ; do
- NB=$(echo "$files" | wc -l )
- percentage=$( bc -l <<< "scale=2; $i * 100 / $NB" )
- printf '%7d/%d : %3.2f%%\n' "$i" "$NB" "$percentage"
- echo -en "\e[1A"
- file=$(echo "$files" | sed -n '1p' ) #read the first line (file)
- files=$(echo "$files" | sed "1d" ) #remove the line we just read
- size=$(stat -c%s "$file")
- while read -r l ; do
- s=$(stat -c%s "$l")
- if (( $s == $size )) ; then
- [[ ! -f "$outputDir/$i" ]] && echo "$file" > "$outputDir/$i" #save the file
- echo "$l" >> "$outputDir/$i" #and its duplicate
- fi
- done <<< "$files"
- if [[ -f "$outputDir/$i" ]] ; then
- while read -r ll ; do
- files=$(echo "$files" | sed "\|$ll|d" ) #remove the file and its duplicates from the list
- done < "$outputDir/$i" #to speed up the process
- fi
- (( $NB <=1 )) && break
- i=$((i+1))
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement