From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.gentoo.org ([140.105.134.102] helo=robin.gentoo.org) by nuthatch.gentoo.org with esmtp (Exim 4.62) (envelope-from ) id 1I7fpd-0007wq-CJ for garchives@archives.gentoo.org; Sun, 08 Jul 2007 23:06:21 +0000 Received: from robin.gentoo.org (localhost [127.0.0.1]) by robin.gentoo.org (8.14.0/8.14.0) with SMTP id l68N54Vm015888; Sun, 8 Jul 2007 23:05:04 GMT Received: from mail.askja.de (mail.askja.de [83.137.103.136]) by robin.gentoo.org (8.14.0/8.14.0) with ESMTP id l68N0aqx011017 for ; Sun, 8 Jul 2007 23:00:37 GMT Received: from xdsl-213-196-211-172.netcologne.de ([213.196.211.172] helo=zone.wonkology.org) by mail.askja.de with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.67) (envelope-from ) id 1I7fk4-0003o8-9E for gentoo-user@lists.gentoo.org; Mon, 09 Jul 2007 01:00:36 +0200 Received: from weird.wonkology.org (weird.wonkology.org [::ffff:192.168.1.4]) by zone.wonkology.org with esmtp; Mon, 09 Jul 2007 01:00:22 +0200 id 0003006A.46916C86.00007DC0 From: Alex Schuster Organization: Wonkology To: gentoo-user@lists.gentoo.org Subject: Re: [gentoo-user] Change the case of file names Date: Mon, 9 Jul 2007 01:00:21 +0200 User-Agent: KMail/1.9.5 References: <200707022159.27096.michaelkintzios@gmail.com> <200707022347.54400.wonko@wonkology.org> <200707082218.12807.michaelkintzios@gmail.com> In-Reply-To: <200707082218.12807.michaelkintzios@gmail.com> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@gentoo.org Reply-to: gentoo-user@lists.gentoo.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200707090100.21779.wonko@wonkology.org> X-Archives-Salt: b7e7ec17-e5b4-4de3-a8f2-14419b1d0a51 X-Archives-Hash: 1f6bd0eee025655d19806861f184027a Mick writes: > Thanks Alex, I was trying your script, but just like Etaoin's script it > does not go beyond level 1 in the directory. All the subdirectories and > files within them stay in Capital Case. > > How can I change it to recursively look into the directory? That's strange. I tried that and had no problem. Here's a slightly enhanced version with more options. -h shows a help, -d=20 also converts directories, -r turns recursive operation on, and -u would=20 convert into uppercase instead. So you would use it like that: lowercase -dr * This assumes you also want the directory names converted. Leave the -d=20 option off if not. And add a -t first so you see what would be done, in=20 case the script would mess things up. It seems to work, but was written=20 rather quickly. If all seems okay, start it again without the -t. If it still don't work, you can also use the find command to process each=20 file individually: find . -exec lowercase -d \{\} \; Or this if you like to change files only: find . -type f -exec lowercase \{\} \; =09 =46eel free to email me directly if you are still having trouble, so we won= 't=20 bother the list. Alex #!/bin/bash # parse options unset oDir oRec oTest oUpper while getopts "dhrtu" opt do case $opt in h ) echo " ${0##*/} [-dhrtu] files... Convert files into lowercase Options: -d convert directories, too -h show this help -r recursive -t test, show what would be done -u change to uppercase instead " exit 0 ;; d ) oDir=3Dtrue ;; r ) oRec=3Dtrue ;; t ) oTest=3Dtrue ;; u ) oUpper=3Dtrue ;; * ) exit 1 esac done shift $(( OPTIND-1 )) # decide whether to convert to lowercase or uppercase if [[ $oUpper ]] then from=3D[:lower:] to=3D[:upper:] else from=3D[:upper:] to=3D[:lower:] fi # make * expand to empty string when no files are found shopt -s nullglob # loop over arguments while (( $# )) do aFile=3D$1 shift =09 # check if file exists if ! [[ -e $aFile ]] then echo "File not found: '$aFile'" continue fi =09 # process directories recursively first if [[ -d $aFile ]] && [[ $oRec ]] && [[ $aFile/* ]] then $0 ${oDir:+-d} ${oTest:+-t} ${oUpper:+-u} -r "$aFile"/* fi =09 # skip directories without -d option [[ -d $aFile ]] && ! [[ $oDir ]] && continue =09 # create new name dir=3D$( dirname "$aFile" ) base=3D$( basename "$aFile" ) newFile=3D${dir:+$dir/}$( echo "$base" | tr "$from" "$to" ) =09 # rename file if necessary [[ $aFile -ef $newFile ]] || ${oTest:+echo} mv -v "$aFile" "$newFile" done wonko@weird test --> ../lowercase -rd * =BBA/A/X=AB -> =BBA/A/x=AB =BBA/A/Y=AB -> =BBA/A/y=AB =BBA/A=AB -> =BBA/a=AB =BBA=AB -> =BB./a=AB =BBB/B=AB -> =BBB/b=AB =BBB=AB -> =BB./b=AB =BBC/X=AB -> =BBC/x=AB =BBC=AB -> =BB./c=AB =BBX=AB -> =BB./x=AB =BBY=AB -> =BB./y=AB -- gentoo-user@gentoo.org mailing list