-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_jpeg_duplicates.sh
executable file
·104 lines (91 loc) · 1.87 KB
/
remove_jpeg_duplicates.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
# Init variables
isSetM=0
isSetD=0
isSetE=0
isSetCount=0
counter=0
#Display usage info
usage() {
cat <<EOF
Usage: dng-jpg.sh [-m <path>] [-d <path>] [-e <path>] [-h]
-m: for move (moves files to <path>/duplicates)
-d: for delete (deletes duplicate files)
-e: for echo (lists duplicate files)
-h: for help
EOF
exit 1
}
#Check for parameters
while getopts ":m:d:e:h" opt; do
case ${opt} in
m)
isSetM=1
let isSetCount="$isSetCount+1"
arg=${OPTARG}
echo "Move selected with path:" $arg
;;
d)
isSetD=1
let isSetCount="$isSetCount+1"
arg=${OPTARG}
echo "Delete selected with path:" $arg
;;
e)
isSetE=1
let isSetCount="$isSetCount+1"
arg=${OPTARG}
echo "Echo selected with path:" $arg
;;
h)
let isSetCount="$isSetCount+1"
usage
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
:)
echo "Option -$OPTARG requires a directory argument." >&2
usage
;;
*)
usage
;;
esac
done
# If no parameters, show usage help and exit
if test -z "$1"; then
usage
fi
# If multiple parameters (not counting -a), show usage help and exit
if (($isSetCount > 1)); then
usage
fi
#Verify directory
if [ ! -d "${arg}" ]; then
echo "$arg is not a path to a directory." >&2
usage
fi
#Now set it as a basedir
BASEDIR=$arg
WASTEDIR="$BASEDIR/duplicates/"
if (( $isSetM==1 )); then
mkdir $WASTEDIR
fi
find "${BASEDIR}" -name '*.RAF' | while read LINE; do
prefix=${LINE%.RAF}
if [ -e "$prefix.JPG" ]; then
let counter="$counter+1"
if (( $isSetE==1 )); then
echo "$prefix.JPG"
fi
if (( $isSetM==1 )); then
mv $prefix.JPG $WASTEDIR
fi
if (( $isSetD==1 )); then
rm "${prefix}.JPG"
fi
fi
done
echo "$counter files found."