Skip to content

Commit 31d5535

Browse files
author
cbxcube
committed
Adding dupfinder-ng.sh
1 parent b32e155 commit 31d5535

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

dupfind-ng.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
# find duplicates in folder which is provided as $1 to the script
4+
5+
clear
6+
7+
printf " Starting duplicate finder program by Cubic(c)2019.\n"
8+
9+
folder=$1
10+
11+
listfiles=/tmp/listfiles
12+
listmd5cs=/tmp/listmd5cs
13+
listdupnr=/tmp/listdupnr
14+
listdupls=/tmp/listdupls
15+
16+
17+
get_file_list() {
18+
#cd $folder
19+
find $folder -type f -print0 |xargs -0 -i echo "{}"|sort > $listfiles
20+
}
21+
22+
get_md5sum() {
23+
#for i in "$(cat $listfiles)"; do md5sum "$i"; done > $listmd5cs
24+
cat $listfiles |while read line; do md5sum "$line"; done > $listmd5cs
25+
}
26+
27+
get_dupnum() {
28+
cat $listmd5cs | awk '{print $1}' |uniq -c |grep -v ^......1 > $listdupnr
29+
}
30+
31+
get_duplist() {
32+
for i in $(cat $listdupnr); do grep "$i" $listmd5cs >> $listdupls; done
33+
}
34+
35+
get_duplsout() {
36+
printf "================================================================\n"
37+
printf " List of identified duplicates in $folder\n"
38+
printf "================================================================\n"
39+
#for i in $(cat $listdupnr|awk '{print $2}'); do grep "$i" $listmd5cs; done |awk '{print $2}' > $listdupls
40+
#cat $listdupnr|awk '{print $2}'|while read line; do grep "$i" $listmd5cs; done |awk '{print $2}' > $listdupls
41+
awk '{print $2}' $listdupnr |while read line; do grep "$line" $listmd5cs; done |awk '{print $2}' > $listdupls
42+
for i in "$(cat $listdupls)"; do ls -lh "$i"; done;
43+
}
44+
45+
cleanup() {
46+
rm $listfiles $listmd5cs $listdupnr $listdupls
47+
}
48+
49+
# RUNTIME:
50+
51+
get_file_list
52+
get_md5sum
53+
get_dupnum
54+
get_duplist
55+
get_duplsout
56+
57+
printf "================================================================\n"
58+
59+
### Check if all files has been uniq. if yes exit, if no list duplicates.
60+
61+
if [ "$(wc -l < $listfiles)" -eq "$(wc -l < $listdupls)" ]; then
62+
printf " No duplicates detected\n"
63+
else
64+
printf " Duplicate files has been found. Exiting the program.\n"
65+
fi
66+
67+
# Clean temporary files
68+
#cleanup
69+
70+
exit 0

0 commit comments

Comments
 (0)