-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirdups
More file actions
executable file
·93 lines (77 loc) · 2.08 KB
/
Copy pathdirdups
File metadata and controls
executable file
·93 lines (77 loc) · 2.08 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
# shopt -s inherit_errexit
# set -euo pipefail
# IFS=$'\n\t'
# set -x
export PS4='`[[ $? == 0 ]] || echo "\e[1;31;40m($?)\e[m\n "`:.$LINENO:'
die() { echo >&2 "$*"; exit 1; }
x() { set -x; "$@"; { set +x; } 2>/dev/null; }
[[ -z "${1:-}" ]] && {
echo >&2 "Usage:
$0 dir1 dir2
OR
$0 dir1 a > /tmp/1
$0 dir2 b > /tmp/2
cd /tmp
$0 dups
NOTE: /tmp/1 and /tmp/2, are hardcoded
Output will open up in vim. Lines will look like (tab-sep):
339 337 a/personal 337 b/personal
296 296 a/private 296 b/private
normally f1 <= f2, <= f4 (you can't have more matches than there are files!)
but if f1 > either f2 or f4, it means there are dups in that subdir
NOTE that this is not as useful as vifm :compare if there are lots of file and
dir renames.
"
exit
}
# ----------------------------------------------------------------------
_b3() (
cd $1
find . -type f |
xxh128sum --filelist - |
sed -e 's/ /\t/' -e 's/\t\.\//\t'$2'\//' |
sort
)
# ----------------------------------------------------------------------
if [[ -d ${2:-} ]]
then
_b3 $1 a > /tmp/1
_b3 $2 b > /tmp/2
elif [[ $2 =~ ^[ab]$ ]]
then
_b3 $1 $2
exit
elif [[ $1 == dups ]]
then
:
else
die '???'
fi
# ----------------------------------------------------------------------
cd /tmp
join -j 1 -t $'\t' 1 2 | cut -f2,3 > 12
cp 12 12o
rm -f 12c
while grep -e '^a/..*'$'\t''b/.' < 12 > 12ab
do
sed -e 's,/[^/]*\t,\t,' -e 's,/[^/]*$,,' < 12ab > 12
cat 12 >> 12c
# wc 12 12o 12c
# vifm-pause
done
sort < 12c | uniq -c | sort -rn > 12cs
cat 12cs | perl -n -E '
chomp;
die "BAD $_" unless m(^ *(\d+) *(a.*)\t(b.*));
$n = $1; $a = $2; $b = $3;
BEGIN {
local @ARGV = qw(1); @a = <>; chomp(@a);
local @ARGV = qw(2); @b = <>; chomp(@b);
}
$ac = grep(/$a/, @a);
$bc = grep(/$b/, @b);
say "$n\t$ac\t$a\t$bc\t$b";
# say "possible duplicates in above dir(s)" if $n > $ac or $n > $bc;
' > 12counts
vim -c 'set ts=16' 12counts