This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.
Subject: Re: convert file names to low case From: Thomas Porter <txporter@mindspring.com> Date: Tue, 4 May 1999 11:46:45 -0400 On Tue, May 04, 1999 at 10:16:42AM -0400, Thomas Porter thoughtfully expounded: > > I have followed this thread, but have a slightly more interesting problem: > > I have a couple of CD's that must have been burned on a Windows system, since > the filenames on the cd do not match the case of the filenames in the html, so > there are lots of broken links sprinkled around. > > Is there an option to the mount command that would make filenames > case-insensitive? Any kind of option in Netscape to do the same? OK, to answer my own question, if one mounts the cd with options 'check=relaxed, norock' this causes case-munging. See the mount man page in the ISO9660(?) section for details. === Subject: Re: replacing RedHat 6.0's KDE From: "Steve \"Stevers!\" Coile" <scoile@redhat.com> Date: Fri, 14 May 1999 12:56:38 -0400 (EDT) On Fri, 14 May 1999, Jose M. Sanchez wrote: > Can you tell me how to change every UPPERCASE file name and suffix in a > directory to lowercase using a single line command? Untested, USE AT YOUR OWN RISK ls | while read f do [ -f "$f" ] && mv -f "$f" "`echo \"$f\" | tr A-Z a-z`" done === Subject: Re: convert file names to low case From: John H Darrah <jhd@giddens.com> Date: Mon, 3 May 1999 09:26:17 -0700 (PDT) On Mon, 3 May 1999, Michael George wrote: > On May 01, Anthony Baratta wrote: > > John H Darrah wrote: > > > > > #!/bin/bash > > > for F in * > > > do mv $F $(echo $F | tr A-Z a-z) > > > done > > > > Man....5 lines in a shell script versus 41 lines in a Perl Script...even > > if I cut out the comments and other 'superfluous' code...its 5 versus > > 12. > > Just off the top of my head, I think we could trim that to one command and > also catch all the entries in the filetree: > > find . -exec mv {} $(echo {} | tr [:upper:] [:lower:] ) \; > Because 'find' runs a "command", not a shell construct. For the above to work you would have to do this: find . -exec bash -c 'mv {} $(echo {} | tr [:upper:] [:lower:] )' \; ====== Subject: Re: convert file names to low case From: "Fred Lenk RHL Linux account" <fllnx@commpower.com> Date: Mon, 3 May 1999 13:36:37 -0700 Here's a quicky. $i is the existing filename, $ii is the converted filename. And simply reverse the upper/lower ordering in the tr command to go from lower to upper if you're debugging. fred ================ cut here =========== #convert uppercase filenames to lowercase for i in `ls` do #ii=`echo $i | tr A-Z a-z` #this works too ii=`echo $i | tr '[:upper:]' '[:lower:]' ` echo $ii #debugging #uncomment following line after debugged #mv $i $ii done === Subject: Re: convert file names to low case From: Joe Brenner <doom@kzsu.Stanford.EDU> Date: Mon, 03 May 1999 16:10:35 -0700 John H Darrah <jhd@giddens.com> wrote: > On Mon, 3 May 1999, Michael George wrote: > > > On May 01, Anthony Baratta wrote: > > > John H Darrah wrote: > > > > > > > #!/bin/bash > > > > for F in * > > > > do mv $F $(echo $F | tr A-Z a-z) > > > > done > > > > > > Man....5 lines in a shell script versus 41 lines in a Perl Script...even > > > if I cut out the comments and other 'superfluous' code...its 5 versus > > > 12. > > > > Just off the top of my head, I think we could trim that to one command and > > also catch all the entries in the filetree: > > > > find . -exec mv {} $(echo {} | tr [:upper:] [:lower:] ) \; > > > > Because 'find' runs a "command", not a shell construct. For > the above to work you would have to do this: > > find . -exec bash -c 'mv {} $(echo {} | tr [:upper:] [:lower:] )' \; Well let's see. If I needed to do this to a bunch of files in the current directory, I'd probably use a keystroke macro in emacs: emacs . C-x C-q # turn off write protection C-x ( # start recording a macro C-k C-y # kill and restore the line to put a copy on the kill-ring R # dired's rename command C-y # yank a copy of the original name C-r / C-f # skip back to the last / (start of file name) <return> ! # do rename, and approve any overwrites C-x ) # to finish recording the macro #then to execute the macro repeatedly a huge number of times: C-u C-u C-u C-u C-u C-x e So that's around 29 keystrokes, versus about 63 for the command line approach. Though while doing a recursive descent like "find" would be possible in emacs, it might be a little awkward. So if that's a requirement of the problem, maybe the CLI paradigm wins this particular contest. ====== Subject: Re: convert file names to low case From: Hans Juergen von Lengerke <hans@knowledgepool.com> Date: Tue, 4 May 1999 07:38:51 +0100 (GMT) On Mon, 3 May 1999, Zaigui Wang wrote: > What if you just want to change the first letter, not all of them? You can use Larry Wall's 'rename' perl script. To convert the first letter from, say, lower case to upper case for all .html files call it like this: rename 's/^([a-z])/\u$1/' *.html The rename script is about as flexible as it gets when it comes to renaming many files. Save the script below as 'rename' somewhere in your path (/usr/local/bin is probably the appropriate place for it - ~/bin if you're not the admin of your system) and call it with 'rename --help' to print the usage. The script will be of little help if you don't know Perl's regular expressions. HTH, Hans ----------- rename ------------------------------------------------- #!/usr/local/bin/perl $op = shift || die "Usage: rename expr [files]\n"; if ($op =~ m/^--?h/i) { print <<'HELP'; Usage: rename expr [files] Examples: rename 's/\.orig$//' *.orig rename 'y/A-Z/a-z/ unless /^Make/' * rename '$_ .= ".bad"' *.f rename 'print "$_: "; s/foo/bar/ if <stdin> =~ /^y/i' * HELP exit; } for (@ARGV) { $was = $_; eval $op; die $@ if $@; rename($was,$_) unless $was eq $_; } ------ end rename ------------------------------------------------- ===