#!/bin/bash #.Y / 70 83 / / / / 105 / / / / / / ;A4_QUER.Y #.YT 3 2 0 0 3 3 1 / / / #.H!a!0:linux//io/f_/map_/THIS!0.!c # # copyright : (C) 2009 by Thomas Bruecker =: tbrue # email : public0x05bf@bluewin.ch # # tbrue 31oct2007 # # f_ map_ THIS : (math)-map utilities for files #++++++++++++++++++++++++++++++++++++++++++++++ # # MyHash("linux//io/f_/map_/THIS") = 0x0B0F # # * for every function: # * if returned result is not commented, the function returns 0 on no-error. # # temp: SCRIPTS=root/bin f_map_Md5Sums() # * working folder := "./" ( 'pwd' ). # * 1. calculate md5sums on regular files in the working folder and its sub- # folders by descending recursively into them. # * 2. sort the list of (1.) by path-names relative to the working folder. # * 3. print progress (folders working on) to stderr; print result of (2.) # to stdout. # * returns 0 . { # * tbrü 10mar2007: no difference in searching on an vfat fs between "" and # "-noleaf" . maybe better anyway to use "-noleaf" . # avoid differing sorting orders on different systems: LC_ALL=C export LC_ALL find -noleaf -type d -fprint /dev/stderr \ -exec find {} -maxdepth 1 -type f -print0 \; \ | xargs -0 md5sum -b \ | sort -f -k 2 } f_map_Md5SumsInFolder() # $1 : path to "working"-folder. # $2 : name of "output-file". # * calculate md5sums in "working"-folder according to "f_map_Md5Sums()" and # write them to "output-file"; "output-file" is written or overwritten in # "working"-folder. { local Md5SumsFile0x0B0F OutputFile0x0B0F WorkingPath0x0B0F WorkingPath0x0B0F="${1}" OutputFile0x0B0F="${2}" pushd $(pwd) > /dev/null cd "${WorkingPath0x0B0F}" # delete old md5sums-file first: rm -f ${OutputFilename0x0B0F} # create temporary md5sums-file: Md5SumsFile0x0B0F="$( mktemp "../${OutputFile0x0B0F}.XXXXXX" )" f_map_Md5Sums > "${Md5SumsFile0x0B0F}" mv -f "${Md5SumsFile0x0B0F}" ${OutputFile0x0B0F} popd > /dev/null }