commit 33de113af57757d98950dfa0590804a98970c53d
parent 3444c74c2b37a41bdd75070483dc205d4987a3f1
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date: Wed, 13 Oct 2010 18:32:11 +0200
Nouveaux scripts + corrections dans les anciens.
Diffstat:
4 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/quickhash b/quickhash
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+find "$@" -type f -printf "%s %p\n" | while read ab; do
+ sum="$(printf %8.8x "${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}" != "40" ]; then
+ sum="0000000000000000000000000000000000000000"
+ fi
+ echo "$sum $nom"
+done
diff --git a/remdoubles b/remdoubles
@@ -48,7 +48,7 @@ sort | while read ab; do
if [ "$sum" != "$oldsum" ]; then
if [ -n "$orig" ]; then
for i in "${supprimable[@]}"; do
- if diff -q "$orig" "$i"; then
+ if diff -q "$orig" "$i" > /dev/null; then
echo "rm '${i//\'/$q}'"
fi
done
diff --git a/showdoubles b/showdoubles
@@ -0,0 +1,57 @@
+#!/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
diff --git a/showunique b/showunique
@@ -35,7 +35,7 @@ sort | while read ab; do
if [ "$sum" != "$oldsum" ]; then
if [ -n "$orig" ]; then
for i in "${supprimable[@]}"; do
- if diff -q "$orig" "$i"; then
+ if diff -q "$orig" "$i" > /dev/null; then
:
else
# Pas de clone à l'extérieur, on affiche.