-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdupes
More file actions
executable file
·71 lines (60 loc) · 1.65 KB
/
dupes
File metadata and controls
executable file
·71 lines (60 loc) · 1.65 KB
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
#!/bin/bash
# Check if a search term is provided
if [ -z "$1" ]; then
echo "Usage: $0 <filename-pattern>"
exit 1
fi
# Define the search directory (current directory by default)
SEARCH_DIR=${2:-.}
# Find files matching the pattern
echo "Searching for files matching '$1' in '$SEARCH_DIR'..."
FILES=()
while IFS= read -r file; do
FILES+=("$file")
done < <(find "$SEARCH_DIR" -type f -iname "*$1*" 2>/dev/null)
# If no files found, exit
if [ ${#FILES[@]} -eq 0 ]; then
echo "No matching files found."
exit 0
fi
# Display found files
echo -e "\nResults are:"
for file in "${FILES[@]}"; do
echo "$file"
done
# Function to check if two files are identical
are_files_identical() {
cmp -s "$1" "$2"
}
# Group identical files
GROUPED_FILES=() # Holds lists of identical files
UNIQUE_FILES=() # Holds unique files
for file in "${FILES[@]}"; do
MATCH_FOUND=false
for i in "${!GROUPED_FILES[@]}"; do
ref_file=${GROUPED_FILES[$i]%% *} # Get the first file in the group
if are_files_identical "$file" "$ref_file"; then
GROUPED_FILES[$i]="${GROUPED_FILES[$i]} $file"
MATCH_FOUND=true
break
fi
done
if [ "$MATCH_FOUND" = false ]; then
GROUPED_FILES+=("$file")
UNIQUE_FILES+=("$file")
fi
done
# Display grouped files
echo -e "\nIdentical files:"
for group in "${GROUPED_FILES[@]}"; do
if [[ "$group" == *" "* ]]; then
echo "$group are all the same file with different names."
fi
done
# Display unique files
echo -e "\nUnique files:"
for file in "${UNIQUE_FILES[@]}"; do
if [[ "$file" != *" "* ]]; then
echo "$file is unique"
fi
done