On Mon, Jul 02, 2007 at 09:59:17PM +0100, Penguin Lover Mick squawked: > Hi All, > > I backed up my wife's WinXP fs using K3B and I used default settings which > unfortunately converted all file names to CAPITALS and shortened them to 8 > characters maximum, just like DOS would do. Is there a clever way to change > some of them back to lower case (in batches within given directorates) so > that she doesn't have to do it manually one by one? I do not want to change > the access times, only the filename case letters.
from 'info sed' -> Examples #! /bin/sh # rename files to lower/upper case... # # usage: # move-to-lower * # move-to-upper * # or # move-to-lower -R . # move-to-upper -R . # help() { cat << eof Usage: $0 [-n] [-r] [-h] files... -n do nothing, only see what would be done -R recursive (use find) -h this message files files to remap to lower case Examples: $0 -n * (see if everything is ok, then...) $0 * $0 -R . eof } apply_cmd='sh' finder='echo "$@" | tr " " "\n"' files_only= while : do case "$1" in -n) apply_cmd='cat' ;; -R) finder='find "$@" -type f';; -h) help ; exit 1 ;; *) break ;; esac shift done if [ -z "$1" ]; then echo Usage: $0 [-h] [-n] [-r] files... exit 1 fi LOWER='abcdefghijklmnopqrstuvwxyz' UPPER='ABCDEFGHIJKLMNOPQRSTUVWXYZ' case `basename $0` in *upper*) TO=$UPPER; FROM=$LOWER ;; *) FROM=$UPPER; TO=$LOWER ;; esac eval $finder | sed -n ' # remove all trailing slashes s/\/*$// # add ./ if there is no path, only a filename /\//! s/^/.\// # save path+filename h # remove path s/.*\/// # do conversion only on filename y/'$FROM'/'$TO'/ # now line contains original path+file, while # hold space contains the new filename x # add converted file name to line, which now contains # path/file-name\nconverted-file-name G # check if converted file name is equal to original file name, # if it is, do not print nothing /^.*\/\(.*\)\n\1/b # now, transform path/fromfile\n, into # mv path/fromfile path/tofile and print it s/^\(.*\/\)\(.*\)\n\(.*\)$/mv "\1\2" "\1\3"/p ' | $apply_cmd ..... which is probably a bit of an overkill. (And don't ask me why I remember this particular example being in the sed info page ;p ) HTH, W -- "`The best way to get a drink out of a Vogon is to stick your finger down his throat...'" - The Book, on one of the Vogon's social inadequacies. Sortir en Pantoufles: up 206 days, 20:29 -- [EMAIL PROTECTED] mailing list