[comp.unix.xenix] Filenames -- converting

srb@beta.lanl.gov ( Steve Berger ) (06/08/89)

 I have a directory with all the filenames in Uppercase letters.
 I'd like to move them all to lowercase.

 Is there an easy way to do that?  I figure there must be a way using
 sed  or something, but I haven't figured it out yet, and I don't want to
 go thru and  use  mv to move each file name, that will take me forever.

 Any ideas will be appreciated.

 Steve Berger

 srb@lanl.gov

wrp@biochsn.acc.Virginia.EDU (William R. Pearson) (06/09/89)

In article <25879@beta.lanl.gov> srb@beta.UUCP ( Steve Berger ) writes:
>
> I have a directory with all the filenames in Uppercase letters.
> I'd like to move them all to lowercase.
>
> Is there an easy way to do that?  I figure there must be a way using
> sed  or something, but I haven't figured it out yet, and I don't want to
> go thru and  use  mv to move each file name, that will take me forever.
>
> Any ideas will be appreciated.
>
> Steve Berger
>
> srb@lanl.gov


	Here is a program called tolower, that takes an argument and
returns it in lowercase.  Compile it and use the csh script:

	foreach file (*)
	mv $file  `tolower $file`
	end

======== tolower.c ==========

/*	tolower.c

	converts argument to lowercase on stdout
*/

#include <stdio.h>

main(argc,argv)
	int argc; char **argv;
 {
	if (argc > 1) {lowers(argv[1]); printf("%s",argv[1]); exit(0);}
	else exit(1);
	}

lowers(str)
	char *str;
{
	char tolower();
	for (; *str; str++) *str = tolower(*str);
	}

char tolower(chr)
	char chr;
{
	if (chr>='A'&& chr<='Z') return chr-'A'+'a';
	else return chr;
	}

conan@vax1.acs.udel.EDU (Robert B Carroll) (06/09/89)

In article <25879@beta.lanl.gov> srb@beta.UUCP ( Steve Berger ) writes:
>
> I have a directory with all the filenames in Uppercase letters.
> I'd like to move them all to lowercase.
>
> Is there an easy way to do that?  I figure there must be a way using
> sed  or something, but I haven't figured it out yet, and I don't want to
> go thru and  use  mv to move each file name, that will take me forever.
>
fat chance of changing the name of a file unless you either copy it
or 'mv' it. doing a 'mv' doesn't take to much time.
unless you hack around with the inode table and stuff.
-- 
conan@vax1.acs.udel.edu OR conan@192.5.57.1
CONAN THE BARBARIAN of Cimmeria

maart@cs.vu.nl (Maarten Litmaath) (06/09/89)

srb@beta.lanl.gov ( Steve Berger ) writes:
\ I have a directory with all the filenames in Uppercase letters.
\ I'd like to move them all to lowercase.

for i in *
do
	mv $i `echo $i | tr '[A-Z]' '[a-z]'`
done
-- 
 "Your password [should be] like your |Maarten Litmaath @ VU Amsterdam:
      toothbrush." (Don Alvarez)      |maart@cs.vu.nl, mcvax!botter!maart

ked@garnet.berkeley.edu (Earl H. Kinmonth) (06/09/89)

In article <25879@beta.lanl.gov> srb@beta.UUCP ( Steve Berger ) writes:
>
> I have a directory with all the filenames in Uppercase letters.
> I'd like to move them all to lowercase.
>
> Is there an easy way to do that?  I figure there must be a way using
> sed  or something, but I haven't figured it out yet, and I don't want to
> go thru and  use  mv to move each file name, that will take me forever.
>
> Any ideas will be appreciated.
>
> Steve Berger
>
> srb@lanl.gov

There are many ways you can do this.  The one given below works.  It
is not necessarily "efficient" except that it took me about 1 second
to think it through.

for i in *
do
T=`echo $i | tr '[A-Z]' '[a-z]`
mv $i $T
done

If you want to do it with sed, look at the "y" command.

Earl H. Kinmonth
History Department
University of California, Davis
Davis, California  95616
916-752-1636 (2300-0800 PDT for FAX)
916-752-0776 (secretary)
ucbvax!ucdavis!ucdked!cck (email)
cc-dnet.ucdavis.edu [128.120.2.251]
	(request ucdked, login as guest)

dyer@spdcc.COM (Steve Dyer) (06/09/89)

In article <1613@hudson.acc.virginia.edu> wrp@biochsn.acc.Virginia.EDU.acc.Virginia.EDU (William R. Pearson) writes:
>Here is a program called tolower, that takes an argument and returns it in
>lowercase.  Compile it and use the csh script:
>	foreach file (*)
>	mv $file  `tolower $file`
>	end

Oh, you mean:

foreach file (*)
       mv $file  `echo $file | tr '[A-Z]' '[a-z]'`
end

-- 
Steve Dyer
dyer@ursa-major.spdcc.com aka {ima,harvard,rayssd,linus,m2c}!spdcc!dyer
dyer@arktouros.mit.edu

mbrands@idca.tds.PHILIPS.nl (Manfred Brands) (06/09/89)

In article <25879@beta.lanl.gov> srb@beta.UUCP ( Steve Berger ) writes:
>
> I have a directory with all the filenames in Uppercase letters.
> I'd like to move them all to lowercase.
>
Try:

	for file in *
	do
		mv $file `echo $file | tr '[A-Z]' '[a-z]'`
	done

I use it when I have transferred files from my DOS system to a UNIX system
using Kermit.

Manfred.

-- 
# Manfred Brands                       INTERNET:  mbrands@idca.tds.philips.nl #
# Philips TDS, Dept. SSP               UUCP:      ...!mcvax!philapd!mbrands   #
# P.O. Box 245                         VOICE:     +31 55 432097               #
# 7300 AE Apeldoorn, The Netherlands                                          #

mrm@sceard.UUCP (M.R.Murphy) (06/14/89)

In article <25879@beta.lanl.gov> srb@beta.UUCP ( Steve Berger ) writes:
>
> I have a directory with all the filenames in Uppercase letters.
> I'd like to move them all to lowercase.
>
> Is there an easy way to do that?  I figure there must be a way using
> sed  or something, but I haven't figured it out yet, and I don't want to
> go thru and  use  mv to move each file name, that will take me forever.
>
> Any ideas will be appreciated.
>
> Steve Berger
>
> srb@lanl.gov

In all of the followups to this posting that I saw, I didn't notice
anyone mention the possible advisability of checking that the
translation to lowercase of the filename in question might produce
a filename that already exists in the directory in question. This, then,
might cause unwanted or unexpected results if some of the simpler scripts
were used verbatim.

Pedantic, eh?

If I had a dime for each time I've spouted "Oops" or stronger 1.8sec
after hitting <CR> with my right little finger, I could buy a good book
on shell programming :-)

Typing FMT DK0:/VE=DK1: in DOS-11 with a source pack on DK0: and
a scratch on DK1: at 2AM comes to mind.

---
Mike Murphy  Sceard Systems, Inc.  544 South Pacific St. San Marcos, CA  92069
mrm@Sceard.COM        {hp-sdd,nosc,ucsd,uunet}!sceard!mrm      +1 619 471 0655

davidsen@sungod.crd.ge.com (William Davidsen) (06/15/89)

In article <895@sceard.UUCP> mrm@sceard.UUCP (0040-M.R.Murphy) writes:

| In all of the followups to this posting that I saw, I didn't notice
| anyone mention the possible advisability of checking that the
| translation to lowercase of the filename in question might produce
| a filename that already exists in the directory in question. 

  The xxu program I suggested includes this checking. If you say "oops"
1.8 sec after doing something you are far more polite than I... what I
usually say is not suitable for posting, and I often say it while the
finger is still pressing down the key, when the brain says "no, stop!",
and the finger muscles say "wait a mo, I'm pressing this RETURN key...
ok, now I'll pull away from it."

  I run shell functions for a few of the things which I most like to
type wrong, as well. Let the computer do the error checking.
	bill davidsen		(davidsen@crdos1.crd.GE.COM)
  {uunet | philabs}!crdgw1!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me