commit eccfc292a17c27353af86f0df395a893cdf60761
parent 33de113af57757d98950dfa0590804a98970c53d
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date: Mon, 14 Mar 2011 19:04:52 +0100
Quelques scripts en plus (non documentés, attention !).
Diffstat:
5 files changed, 131 insertions(+), 2 deletions(-)
diff --git a/hidedoubles.sh b/hidedoubles.sh
@@ -0,0 +1,69 @@
+#!/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 "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
diff --git a/pseudo-empty-dirs.sh b/pseudo-empty-dirs.sh
@@ -0,0 +1,32 @@
+#!/bin/zsh
+
+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 *(N); do
+ if [ "${x[0,2]}" != ".%" ]; then
+ pseudo_empty="0"
+ break;
+ fi
+ done
+ cd ..
+ [ "$pseudo_empty" = "1" ] && [ "${1[0,2]}" != ".%" ] && mv -i -- "$1" ".%$1"
+}
+
+dohide .
diff --git a/quickhash b/quickhash
@@ -1,12 +1,13 @@
#!/bin/sh
find "$@" -type f -printf "%s %p\n" | while read ab; do
- sum="$(printf %8.8x "${ab%% *}")"
+ 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}" != "40" ]; then
+ if [ "${#sum}" != "48" ]; then
+ echo "ERROR : $sum $nom" >&2
sum="0000000000000000000000000000000000000000"
fi
echo "$sum $nom"
diff --git a/quickhash.py b/quickhash.py
@@ -0,0 +1,24 @@
+#!/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
diff --git a/quickhash.py.sh b/quickhash.py.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+find "$@" -type f -printf "%s\n%p\n" | ./quickhash.py