Suppression des anciens scripts que je n'utilise plus.
This commit is contained in:
parent
6cf1a0cc35
commit
997c9044ae
4
README
4
README
|
@ -1,7 +1,3 @@
|
|||
Attention !
|
||||
|
||||
Lisez le code source des scripts avant de les utiliser ! Normalement aucun d'eux ne supprime de fichiers sans une forte confirmation, mais on ne sait jamais...
|
||||
|
||||
De plus, il est possible (en cas de collision de somme de contrôle) que remdoubles ne détecte pas certains doublons (mais il ne fera PAS de faux positifs, il utilise diff pour vérifier que les deux fichiers sont bien identiques avant de signaler un doublon).
|
||||
|
||||
Pour ce qui est de showunique, il est possible qu'il ne signale pas certains fichiers qui n'ont pourtant pas de doublons (en cas de collision de somme de contrôle). Ne lui faites donc pas confiance, il est possible qu'il n'ait pas repéré certains fichiers non doublons.
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import sys
|
||||
import os
|
||||
import errno
|
||||
import shutil
|
||||
|
||||
def identicalFiles(pathA, pathB):
|
||||
bufsize = 4096
|
||||
with open(pathA, 'rb') as a:
|
||||
with open(pathB, 'rb') as b:
|
||||
while True:
|
||||
dataA = a.read(bufsize)
|
||||
dataB = b.read(bufsize)
|
||||
if dataA != dataB:
|
||||
return False
|
||||
if not dataA:
|
||||
return True
|
||||
|
||||
nblines=0
|
||||
for supprimable in sys.stdin:
|
||||
nblines = (nblines+1)%10240
|
||||
if nblines == 0:
|
||||
os.system("sync");
|
||||
original = sys.stdin.next()
|
||||
supprimable = supprimable[0:-1]
|
||||
original = original[0:-1]
|
||||
if supprimable[0:2] == '1/' and os.path.exists(supprimable) and os.path.exists(original) and identicalFiles(original, supprimable):
|
||||
destfile = "delete/" + supprimable
|
||||
try:
|
||||
os.makedirs(os.path.dirname(destfile))
|
||||
except OSError as e:
|
||||
if e.errno == errno.EEXIST:
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
shutil.move(supprimable, destfile);
|
|
@ -1,38 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import sys
|
||||
import os
|
||||
import errno
|
||||
import shutil
|
||||
|
||||
def identicalFiles(pathA, pathB):
|
||||
bufsize = 4096
|
||||
with open(pathA, 'rb') as a:
|
||||
with open(pathB, 'rb') as b:
|
||||
while True:
|
||||
dataA = a.read(bufsize)
|
||||
dataB = b.read(bufsize)
|
||||
if dataA != dataB:
|
||||
return False
|
||||
if not dataA:
|
||||
return True
|
||||
|
||||
nblines=0
|
||||
for supprimable in sys.stdin:
|
||||
nblines = (nblines+1)%10240
|
||||
if nblines == 0:
|
||||
os.system("sync");
|
||||
original = sys.stdin.next()
|
||||
supprimable = supprimable[0:-1]
|
||||
original = original[0:-1]
|
||||
if supprimable[0:2] == '1/' and os.path.exists(supprimable) and os.path.exists(original) and identicalFiles(original, supprimable):
|
||||
destfile = "sync/" + original
|
||||
if not os.path.exists(destfile):
|
||||
try:
|
||||
os.makedirs(os.path.dirname(destfile))
|
||||
except OSError as e:
|
||||
if e.errno == errno.EEXIST:
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
shutil.move(supprimable, destfile);
|
|
@ -1,69 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ -z "$1" -o "$1" == "--help" -o "$1" == "-h" ]; then
|
||||
cat <<EOF
|
||||
Affiche les fichiers qui SONT des doublons, sous forme d'un script
|
||||
permettant leur suppression.
|
||||
Pour afficher les fichiers qui ne sont pas des doublons, utilisez
|
||||
showunique.
|
||||
|
||||
Syntaxe : remdoubles dossier-où-chercher-les-doublons < md5sums
|
||||
|
||||
Exemple :
|
||||
md5sums contient :
|
||||
604c442629170d4bee5804b13e9a587f ./a/fichier_un
|
||||
a3d0c4f97abec8c2ceaaf83020f00809 ./b/fichier_deux
|
||||
a3d0c4f97abec8c2ceaaf83020f00809 ./b/fichier_trois
|
||||
604c442629170d4bee5804b13e9a587f ./b/fichier_XYZ
|
||||
Si on lance "remdoubles ./b/ < md5sums", il affichera
|
||||
#!/bin/sh
|
||||
|
||||
echo Si vous lancez ce script, il supprimera un grand nombre de fichiers dans ./b/ .
|
||||
exit
|
||||
|
||||
rm './b/fichier_XYZ'
|
||||
car il est dans ./b/, ET a un fichier identique ailleurs que
|
||||
dans ./b/ .
|
||||
Il n'affichera pas ./a/fichier_un car il n'est pas dans ./b/
|
||||
Il n'affichera pas ./b/fichier_deux ni ./b/fichier_trois car
|
||||
ils n'ont pas de doublons en dehors de ./b/ .
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "#!/bin/sh"
|
||||
echo ""
|
||||
|
||||
oldsum=""
|
||||
unset supprimable
|
||||
n=0
|
||||
orig=""
|
||||
q="'\\''" # escaped quote.
|
||||
#sort | \
|
||||
while read ab; do
|
||||
sum="${ab%% *}"
|
||||
nom="${ab#* }"
|
||||
if [ "$sum" != "$oldsum" ]; then
|
||||
if [ -n "$orig" ]; then
|
||||
for i in "${supprimable[@]}"; do
|
||||
if true; then # diff -q "$orig" "$i" > /dev/null; then
|
||||
qi="${i//\'/$q}"
|
||||
echo "[ -e '$qi' ] && mv -i '$qi' '${qi%/*}/.%${qi##*/}' # '${orig//\'/$q}'"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
unset supprimable
|
||||
orig=""
|
||||
n=0
|
||||
fi
|
||||
|
||||
if [ "${nom#$1}" != "$nom" ]; then
|
||||
supprimable[n]="$nom"
|
||||
n=$(($n+1))
|
||||
else
|
||||
orig="$nom"
|
||||
fi
|
||||
|
||||
oldsum="$sum"
|
||||
done
|
|
@ -1,28 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import sys
|
||||
import os
|
||||
import errno
|
||||
import shutil
|
||||
|
||||
oldhash = ""
|
||||
original = []
|
||||
supprimable = []
|
||||
nblines=0
|
||||
for line in sys.stdin:
|
||||
nblines = (nblines+1)%500
|
||||
if nblines == 0:
|
||||
os.system("sync");
|
||||
hash = line[0:48]
|
||||
file = line[50:-1]
|
||||
if hash != oldhash:
|
||||
for o,s in zip(original,supprimable):
|
||||
sys.stdout.write(s+"\n"+o+"\0")
|
||||
supprimable = []
|
||||
original = []
|
||||
if file[0:2] == '1/': # Delete files in the directory named 1
|
||||
supprimable.append(file)
|
||||
else:
|
||||
original.append(file)
|
||||
|
||||
oldhash = hash
|
|
@ -1,2 +0,0 @@
|
|||
#!/bin/sh
|
||||
./pre-fast-remdoubles.py | sort -z | tr '\0' '\n'
|
|
@ -1,39 +0,0 @@
|
|||
#!/bin/zsh
|
||||
|
||||
# masque les dossiers qui ne contiennent que des fichiers dont le nom est
|
||||
# .%fichier, récursivement (les dossiers sont masqués en préfixant ".%" à
|
||||
# leur nom, donc les dossiers ne contenant que des fichiers / dossiers
|
||||
# masqués le seront eux aussi.
|
||||
# Un dossier n'est pas masqué ssi il contient au moins un fichier
|
||||
# (regular file) ou dossier non masqué.
|
||||
|
||||
setopt dotglob
|
||||
|
||||
dohide() {
|
||||
local x pseudo_empty subdirs si
|
||||
echo "[$1] $PWD"
|
||||
cd "./$1"
|
||||
pseudo_empty="1"
|
||||
si=1
|
||||
subdirs=()
|
||||
for x in *(N/); do
|
||||
if [ "${x[0,2]}" != ".%" ]; then
|
||||
subdirs[si]="$x"
|
||||
si=$(($si+1))
|
||||
fi
|
||||
done
|
||||
while [ $si -gt 1 ]; do
|
||||
si=$(($si-1))
|
||||
dohide "${subdirs[si]}"
|
||||
done
|
||||
for x in *(/,.NoN); do # N = pas d'erreur quand vide, oN = order none, / = dossiers, . = fichiers
|
||||
if [ "${x[0,2]}" != ".%" ]; then
|
||||
pseudo_empty="0"
|
||||
break;
|
||||
fi
|
||||
done
|
||||
cd ..
|
||||
[ "$pseudo_empty" = "1" ] && [ "${1[0,2]}" != ".%" ] && mv -i -- "$1" ".%$1"
|
||||
}
|
||||
|
||||
dohide .
|
14
quickhash
14
quickhash
|
@ -1,14 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
find "$@" -type f -printf "%s %p\n" | while read ab; do
|
||||
sum="$(printf %16.16x "${ab%% *}")"
|
||||
nom="${ab#* }"
|
||||
mdsum="$(dd if="$nom" bs=512 count=1 2>/dev/null | md5sum 2>/dev/null)"
|
||||
mdsum="${mdsum%% *}"
|
||||
sum="$sum$mdsum"
|
||||
if [ "${#sum}" != "48" ]; then
|
||||
echo "ERROR : $sum $nom" >&2
|
||||
sum="0000000000000000000000000000000000000000"
|
||||
fi
|
||||
echo "$sum $nom"
|
||||
done
|
24
quickhash.py
24
quickhash.py
|
@ -1,24 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import hashlib;
|
||||
import sys;
|
||||
|
||||
for size in sys.stdin:
|
||||
file = sys.stdin.next()
|
||||
print "%16.16x%s" % (int(size), hashlib.md5(open(file[:-1], 'r').read(512)).hexdigest()),
|
||||
print " " + file,
|
||||
|
||||
#!/bin/sh
|
||||
#
|
||||
#find "$@" -type f -printf "%s %p\n" | while read ab; do
|
||||
# sum="$(printf %16.16x "${ab%% *}")"
|
||||
# nom="${ab#* }"
|
||||
# mdsum="$(dd if="$nom" bs=512 count=1 2>/dev/null | md5sum 2>/dev/null)"
|
||||
# mdsum="${mdsum%% *}"
|
||||
# sum="$sum$mdsum"
|
||||
# if [ "${#sum}" != "48" ]; then
|
||||
# echo "ERROR : $sum $nom" >&2
|
||||
# sum="0000000000000000000000000000000000000000"
|
||||
# fi
|
||||
# echo "$sum $nom"
|
||||
#done
|
|
@ -1,3 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
find "$@" -type f -printf "%s\n%p\n" | ./quickhash.py
|
75
remdoubles
75
remdoubles
|
@ -1,75 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ -z "$1" -o "$1" == "--help" -o "$1" == "-h" ]; then
|
||||
cat <<EOF
|
||||
Affiche les fichiers qui SONT des doublons, sous forme d'un script
|
||||
permettant leur suppression.
|
||||
Pour afficher les fichiers qui ne sont pas des doublons, utilisez
|
||||
showunique.
|
||||
|
||||
Syntaxe : remdoubles dossier-où-chercher-les-doublons < md5sums
|
||||
|
||||
Exemple :
|
||||
md5sums contient :
|
||||
604c442629170d4bee5804b13e9a587f ./a/fichier_un
|
||||
a3d0c4f97abec8c2ceaaf83020f00809 ./b/fichier_deux
|
||||
a3d0c4f97abec8c2ceaaf83020f00809 ./b/fichier_trois
|
||||
604c442629170d4bee5804b13e9a587f ./b/fichier_XYZ
|
||||
Si on lance "remdoubles ./b/ < md5sums", il affichera
|
||||
#!/bin/sh
|
||||
|
||||
echo Si vous lancez ce script, il supprimera un grand nombre de fichiers dans ./b/ .
|
||||
exit
|
||||
|
||||
rm './b/fichier_XYZ'
|
||||
car il est dans ./b/, ET a un fichier identique ailleurs que
|
||||
dans ./b/ .
|
||||
Il n'affichera pas ./a/fichier_un car il n'est pas dans ./b/
|
||||
Il n'affichera pas ./b/fichier_deux ni ./b/fichier_trois car
|
||||
ils n'ont pas de doublons en dehors de ./b/ .
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "#!/bin/sh"
|
||||
echo ""
|
||||
echo "echo Si vous lancez ce script, il supprimera un grand nombre de fichiers dans $1 ."
|
||||
echo "exit"
|
||||
echo ""
|
||||
|
||||
oldsum=""
|
||||
unset supprimable
|
||||
n=0
|
||||
orig=""
|
||||
q="'\\''" # escaped quote.
|
||||
#sort | \
|
||||
while read ab; do
|
||||
sum="${ab%% *}"
|
||||
nom="${ab#* }"
|
||||
if [ "$sum" != "$oldsum" ]; then
|
||||
if [ -n "$orig" ]; then
|
||||
for i in "${supprimable[@]}"; do
|
||||
if [ -e "$orig" ] && [ -e "$i" ] && cat "$i" | diff -q "$orig" - > /dev/null; then
|
||||
destdir="delete/${i%/*}"
|
||||
[ -e "$destdir" ] || mkdir -p "$destdir"
|
||||
mv -i "$i" "$destdir"
|
||||
echo -n '.'
|
||||
#echo "myrm '${i//\'/$q}'"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
unset supprimable
|
||||
orig=""
|
||||
n=0
|
||||
fi
|
||||
|
||||
if [ "${nom#$1}" != "$nom" ]; then
|
||||
supprimable[n]="$nom"
|
||||
n=$(($n+1))
|
||||
else
|
||||
orig="$nom"
|
||||
fi
|
||||
|
||||
oldsum="$sum"
|
||||
done
|
|
@ -1,50 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import sys
|
||||
import os
|
||||
import errno
|
||||
import shutil
|
||||
|
||||
def identicalFiles(pathA, pathB):
|
||||
bufsize = 4096
|
||||
with open(pathA, 'rb') as a:
|
||||
with open(pathB, 'rb') as b:
|
||||
while True:
|
||||
dataA = a.read(bufsize)
|
||||
dataB = b.read(bufsize)
|
||||
if dataA != dataB:
|
||||
return False
|
||||
if not dataA:
|
||||
return True
|
||||
|
||||
oldhash = ""
|
||||
original = []
|
||||
supprimable = []
|
||||
for line in sys.stdin:
|
||||
hash = line[0:48]
|
||||
file = line[50:-1]
|
||||
if hash != oldhash:
|
||||
if original != []:
|
||||
for i in supprimable:
|
||||
if os.path.exists(i):
|
||||
for j in original:
|
||||
if os.path.exists(i) and os.path.exists(j) and identicalFiles(j, i):
|
||||
print i + " |||||||||| " + j
|
||||
destfile = "delete/" + i
|
||||
try:
|
||||
os.makedirs(os.path.dirname(destfile))
|
||||
except OSError as e:
|
||||
if e.errno == errno.EEXIST:
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
shutil.move(i, destfile);
|
||||
break
|
||||
supprimable = []
|
||||
original = []
|
||||
if file[0:2] == '1/': # Delete files in the directory named 1
|
||||
supprimable.append(file)
|
||||
else:
|
||||
original.append(file)
|
||||
|
||||
oldhash = hash
|
|
@ -1,52 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import sys
|
||||
import os
|
||||
import errno
|
||||
import shutil
|
||||
|
||||
def identicalFiles(pathA, pathB):
|
||||
bufsize = 4096
|
||||
with open(pathA, 'rb') as a:
|
||||
with open(pathB, 'rb') as b:
|
||||
while True:
|
||||
dataA = a.read(bufsize)
|
||||
dataB = b.read(bufsize)
|
||||
if dataA != dataB:
|
||||
return False
|
||||
if not dataA:
|
||||
return True
|
||||
|
||||
oldhash = ""
|
||||
original = ""
|
||||
supprimable = []
|
||||
nblines=0
|
||||
for line in sys.stdin:
|
||||
nblines = (nblines+1)%500
|
||||
if nblines == 0:
|
||||
os.system("sync");
|
||||
hash = line[0:48]
|
||||
file = line[50:-1]
|
||||
if hash != oldhash:
|
||||
if original != "":
|
||||
for i in supprimable:
|
||||
print i
|
||||
if os.path.exists(i) and identicalFiles(original, i):
|
||||
destfile = "delete/" + i
|
||||
try:
|
||||
os.makedirs(os.path.dirname(destfile))
|
||||
except OSError as e:
|
||||
if e.errno == errno.EEXIST:
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
shutil.move(i, destfile);
|
||||
supprimable = []
|
||||
original = ""
|
||||
if file[0:2] == 'd/': # Delete files in the directory named d
|
||||
supprimable.append(file)
|
||||
else:
|
||||
if original == "" and os.path.exists(file):
|
||||
original = file
|
||||
|
||||
oldhash = hash
|
57
showdoubles
57
showdoubles
|
@ -1,57 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ "$1" == "--help" -o "$1" == "-h" ]; then
|
||||
cat <<EOF
|
||||
Affiche les fichiers qui SONT des doublons, sous forme d'un script
|
||||
permettant leur suppression.
|
||||
Pour afficher les fichiers qui ne sont pas des doublons, utilisez
|
||||
showunique.
|
||||
|
||||
Syntaxe : remdoubles dossier-où-chercher-les-doublons < md5sums
|
||||
|
||||
Exemple :
|
||||
md5sums contient :
|
||||
604c442629170d4bee5804b13e9a587f ./a/fichier_un
|
||||
a3d0c4f97abec8c2ceaaf83020f00809 ./b/fichier_deux
|
||||
a3d0c4f97abec8c2ceaaf83020f00809 ./b/fichier_trois
|
||||
604c442629170d4bee5804b13e9a587f ./b/fichier_XYZ
|
||||
7d4abe4e5104b71312ab56c2f341856e ./b/fichier_pas_de_doublons
|
||||
Si on lance "showdoubles < md5sums", il affichera
|
||||
'./a/fichier_un'
|
||||
'./b/fichier_XYZ'
|
||||
|
||||
'./b/fichier_deux'
|
||||
'./b/fichier_trois'
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
|
||||
oldsum=""
|
||||
oldnom=""
|
||||
unset supprimable
|
||||
first=1
|
||||
q="'\\''" # escaped quote.
|
||||
n=0
|
||||
sort | while read ab; do
|
||||
sum="${ab%% *}"
|
||||
nom="${ab#* }"
|
||||
if [ "$sum" != "$oldsum" ] || ! diff -q "$oldnom" "$nom" > /dev/null; then
|
||||
if [ "$first" != "1" -a "$n" != 1 ]; then
|
||||
echo
|
||||
else
|
||||
echo "$oldnom" >&2
|
||||
fi
|
||||
first=0
|
||||
n=0
|
||||
fi
|
||||
if [ "$n" == 1 ]; then
|
||||
echo "'${oldnom//\'/$q}'"
|
||||
fi
|
||||
if [ "$n" != 0 ]; then
|
||||
echo "'${nom//\'/$q}'"
|
||||
fi
|
||||
n="$((n+1))"
|
||||
|
||||
oldsum="$sum"
|
||||
oldnom="$nom"
|
||||
done
|
65
showunique
65
showunique
|
@ -1,65 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ -z "$1" -o "$1" == "--help" -o "$1" == "-h" ]; then
|
||||
cat <<EOF
|
||||
Affiche les fichiers qui NE SONT PAS des doublons.
|
||||
Pour afficher les doublons, utilisez remdoubles.
|
||||
|
||||
Syntaxe : showunique dossier-où-chercher-les-doublons < md5sums
|
||||
|
||||
Exemple :
|
||||
md5sums contient :
|
||||
604c442629170d4bee5804b13e9a587f ./a/fichier_un
|
||||
a3d0c4f97abec8c2ceaaf83020f00809 ./b/fichier_deux
|
||||
a3d0c4f97abec8c2ceaaf83020f00809 ./b/fichier_trois
|
||||
604c442629170d4bee5804b13e9a587f ./b/fichier_XYZ
|
||||
Si on lance "showunique ./b/ < md5sums", il affichera
|
||||
./b/fichier_deux
|
||||
./b/fichier_trois
|
||||
car ils sont dans ./b/, et n'ont pas de fichiers identiques
|
||||
ailleurs que dans ./b/ .
|
||||
Il n'affichera pas ./a/fichier_un car il n'est pas dans ./b/
|
||||
Il n'affichera pas ./b/fichier_XYZ car il a un doublon
|
||||
en dehors de ./b/ .
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
|
||||
oldsum=""
|
||||
unset supprimable
|
||||
n=0
|
||||
orig=""
|
||||
sort | while read ab; do
|
||||
sum="${ab%% *}"
|
||||
nom="${ab#* }"
|
||||
if [ "$sum" != "$oldsum" ]; then
|
||||
if [ -n "$orig" ]; then
|
||||
for i in "${supprimable[@]}"; do
|
||||
if diff -q "$orig" "$i" > /dev/null; then
|
||||
:
|
||||
else
|
||||
# Pas de clone à l'extérieur, on affiche.
|
||||
echo "$i"
|
||||
fi
|
||||
done
|
||||
else
|
||||
# Pas de clone à l'extérieur, on affiche.
|
||||
for i in "${supprimable[@]}"; do
|
||||
echo "$i"
|
||||
done
|
||||
fi
|
||||
|
||||
unset supprimable
|
||||
orig=""
|
||||
n=0
|
||||
fi
|
||||
|
||||
if [ "${nom#$1}" != "$nom" ]; then
|
||||
supprimable[n]="$nom"
|
||||
n=$(($n+1))
|
||||
else
|
||||
orig="$nom"
|
||||
fi
|
||||
|
||||
oldsum="$sum"
|
||||
done
|
12
unhide.py
12
unhide.py
|
@ -1,12 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import shutil;
|
||||
import sys;
|
||||
|
||||
for dir in sys.stdin:
|
||||
file = sys.stdin.next()
|
||||
if file[0:2] == ".%":
|
||||
dir = dir[:-1]
|
||||
file = file[:-1]
|
||||
shutil.move(dir + '/' + file, dir + '/' + file[2:])
|
||||
print "",
|
|
@ -1,3 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
find "$@" -depth -name '.%*' -printf '%h\n%f\n' | ./unhide.py
|
Loading…
Reference in New Issue
Block a user