How to rename a lot of files into lower case?

How to rename a lot of files into lower case?

Post by Vesselin Bontch » Sun, 01 Sep 1991 00:32:45



Hello, everybody!

When I transfer files from the PC (messy-DOS) to the UNIX machine, my files are
created with names in upper case. I don't like this and want to
convert them into lowercase. Is there an easy and elegant way to do
this? If there are a lot of files, doing it "manually" is boring, and
I couldn't invent a nice shell script that would do the job... Guess
that sed/awk should do, but...

Well, if someone knows how to solve the problem, please post the
solution (or e-mail it to me, if this question has been asked so
frequently, that everybody knows the answer <grin>).

Thanks in advance,
Vesselin

 
 
 

How to rename a lot of files into lower case?

Post by Richard Cze » Sun, 01 Sep 1991 02:32:52



|>When I transfer files from the PC (messy-DOS) to the UNIX machine, my
files are
|>created with names in upper case. I don't like this and want to
|>convert them into lowercase. Is there an easy and elegant way to do
|>this?

If the files are in one directory and you are using C shell try this:

   foreach filename (*)
      mv $filename `echo $filename | tr A-Z a-z`
   end

If you have to traverse through directory trees you have to use find(1).
   MfG
-----------------------------------------------------------------


        P.O.Box 12 40                  phone:  (+49) 2241 14 2039
D-5205 St. Augustin 1, Germany         fax:    (+49) 2241 14 2342
-----------------------------------------------------------------

 
 
 

How to rename a lot of files into lower case?

Post by Jim Wheel » Sun, 01 Sep 1991 02:03:37


|> Hello, everybody!
|>
|> When I transfer files from the PC (messy-DOS) to the UNIX machine, my files are
|> created with names in upper case. I don't like this and want to
|> convert them into lowercase. Is there an easy and elegant way to do
|> this? If there are a lot of files, doing it "manually" is boring, and
|> I couldn't invent a nice shell script that would do the job... Guess
|> that sed/awk should do, but...
|>
|> Well, if someone knows how to solve the problem, please post the
|> solution (or e-mail it to me, if this question has been asked so
|> frequently, that everybody knows the answer <grin>).
|>
|> Thanks in advance,
|> Vesselin
How `bout
#!/bin/sh
# To move files that are upper_case named to lower_case names
#  There are of course MANY other methods, this is just one.
for i in *
do
 mv $i  `echo $i | tr '[A-Z]' '[a-z]'`
done
 
 
 

How to rename a lot of files into lower case?

Post by Doug Gw » Sun, 01 Sep 1991 12:03:12



>... files are created with names in upper case. I don't like this and want to
>convert them into lowercase.

Indeed this is a frequently asked question.  What puzzles me is why people
can't figure out a solution on their own.  Here is how one would go about
analyzing the situation:

I have a bunch of existing files to each of which I wish to apply an
operation (in this case, a renaming operation).  How can I operate on
a bunch of files?  Answer:  There are lots of ways; for example "find"
on a file hierarchy can not only apply operations to files but also
can be used to select some subset of them based on their names, mod
times, types, etc.  If all the files are in the same directory, the
simplest method is usually (assuming a Bourne shell):
        for i in *
        do      # operation on $i goes here
        done

Now to the operation:  For each given filename $i, I want to execute
a command to rename from $i to the lower-case form of $i.  Renaming
is a job for "mv", so what I want is
                mv $i {lower-case form of $i}

The only remaining part of the puzzle is how to produce the lower-case
for of $i, given $i.  This is a standard situation for which "tr" is
well suited:
        tr '[A-Z]' '[a-z]'
filters information from its standard input to its standard output,
replacing upper-case alphabetic characters by lower-case ones and
copying the rest through unchanged.  To make use of this, I need to
get the character string $i onto the standard input of that command,
clearly a job for "echo":
        echo $i | tr ...
Then I need to turn the standard output of that into a string for
the second argument to the "mv" command, clearly a job for the shell
`...` facility.  The complete solution is thus:
        for i in *
        do      mv "$i" `echo "$i" | tr '[A-Z]' '[a-z]'`
        done

To learn more about the use of standard UNIX tools, read Kernighan
and Pike's book "The UNIX Programming Environment", the first half
of which is concerned primarily with exploiting the shell and
standard utilities.

 
 
 

How to rename a lot of files into lower case?

Post by Leslie Mikese » Wed, 04 Sep 1991 12:06:22



>When I transfer files from the PC (messy-DOS) to the UNIX machine, my files are
>created with names in upper case. I don't like this and want to
>convert them into lowercase. Is there an easy and elegant way to do
>this?

The easiest is to avoid it in the first place.  Since you usually will
want the unix filenames in lowercase, the better transfer methods do
it that way automatically.  Kermit and rz/sz will do it if you are
using communications, mtools will do it if you are accessing the dos
disks directly.

Les Mikesell

 
 
 

How to rename a lot of files into lower case?

Post by Rahul Dhe » Thu, 05 Sep 1991 01:31:03



Quote:>    for i in *
>    do      mv "$i" `echo "$i" | tr '[A-Z]' '[a-z]'`
>    done

Regretfully, if you apply this to all files, and there is any filename
conflict after case-folding, you will lose existing files.  Also, if a
filename contains mixed case, chances are you *don't* want to make it
all lowercase.

Attached is my "lfname" script.

===== begin "lfname" script =====
#! /bin/sh
# converts to lowercase
if test $# -lt 1; then
   echo "usage: lfname file ..."
   echo "(specified filenames are converted to lowercase)"
   exit 1
fi


do
   case "$f" in
   *[a-z]*)
      #echo "skipping $f, contains lowercase chars"
      ;;
   *)
      newname=`echo "$f" | tr '[A-Z]' '[a-z]'`
      if test "$newname" != "$f"
      then
         if test -f "$newname"
         then
            echo "$newname already exists"
         else
            mv "$f" "$newname"
         fi
      fi
      ;;
   esac
done
===== end "lfname" script =====
--

UUCP:  oliveb!cirrusl!dhesi
"You're even nuttier than we've come to expect of you." -- Doug Gwyn

 
 
 

How to rename a lot of files into lower case?

Post by Jim Roge » Wed, 04 Sep 1991 23:45:36



Hello, everybody!

Quote:>When I transfer files from the PC (messy-DOS) to the UNIX machine, my files are
>created with names in upper case. I don't like this and want to
>convert them into lowercase. Is there an easy and elegant way to do
>this? If there are a lot of files, doing it "manually" is boring, and
>I couldn't invent a nice shell script that would do the job... Guess
>that sed/awk should do, but...

If you are using ksh you can try the following:

#!/bin/ksh

# Define a variable which will contain only lower case characters

typeset -l lower

# Open a two-way pipe to the "ls" process

ls * |&

# Read from the two-way pipe opened above

while read -p filename
do
        lower=${filename}
# Force upper case characters to lower case
        mv ${filename} ${lower}
done

                        -------------------------

Jim Rogers
Hewlett-Packard Company

 
 
 

How to rename a lot of files into lower case?

Post by Michael Pa » Thu, 05 Sep 1991 15:10:09




> Hello, everybody!

> >When I transfer files from the PC (messy-DOS) to the UNIX machine, my files are
> >created with names in upper case. I don't like this and want to
> >convert them into lowercase. Is there an easy and elegant way to do
> >this? If there are a lot of files, doing it "manually" is boring, and
> >I couldn't invent a nice shell script that would do the job... Guess
> >that sed/awk should do, but...

> If you are using ksh you can try the following:

> #!/bin/ksh
> typeset -l lower
> ls * |&
> while read -p filename
> do
>    lower=${filename}
>    mv ${filename} ${lower}
> done

I'm a novice at writing scripts, but I had to do this and used

#!/bin/sh
for UCFILE  in $* ; do
   LCFILE=`echo $UCFILE | tr '[A-Z]' '[a-z]'`
   mv $UCFILE $LCFILE
done

with a similar script for lower case to upper case.  I then just type lc *
in the appropriate directory (which is the d: drive on my PC simulator).

--
+------------------------------------------------------------------------------+
 Michael Page, Maths Dept, Monash University, Clayton, Victoria, AUSTRALIA 3168

+------------------------------------------------------------------------------+

 
 
 

How to rename a lot of files into lower case?

Post by Dave Ratclif » Wed, 04 Sep 1991 04:26:36



> Hello, everybody!

> When I transfer files from the PC (messy-DOS) to the UNIX machine, my files are
> created with names in upper case. I don't like this and want to
> convert them into lowercase. Is there an easy and elegant way to do
> this? If there are a lot of files, doing it "manually" is boring, and
> I couldn't invent a nice shell script that would do the job... Guess
> that sed/awk should do, but...

Don't know if it's readily available in your neck of the woods but Telix
v. 3.15 automatically uploads files with a lower case file name. If it's
talking to another MessyDos machine, no sweat since it's automatically
moved back to upper case. If it happens to be talking to a Unix system,
then the resultant uploaded file is in lower case already.

While you CAN play around with shell scripts and the tr command, that's
something you'd need to do every time you moved a file onto the Unix
system. With Telix 3.15, you can just forget it.

BTW, Telix is ShareWare. Hope this helps.

            Dave

[----------------------------------------------- Dave Ratcliffe ------------]
: uunet!wa3wbu!compnect!dave        | The Data Factory BBS  Harrisburg  Pa. :



 
 
 

How to rename a lot of files into lower case?

Post by Doug Gw » Thu, 05 Sep 1991 10:04:29




>>        for i in *
>>        do      mv "$i" `echo "$i" | tr '[A-Z]' '[a-z]'`
>>        done
>Regretfully, if you apply this to all files, and there is any filename
>conflict after case-folding, you will lose existing files.  Also, if a
>filename contains mixed case, chances are you *don't* want to make it
>all lowercase.

I was answering the original request, where all the filenames WERE
completely upper case.

In a more general situation, one should follow the other advice I
gave, namely to apply some filename matcher (such as "find" or, in
simple cases, just replace the "*" above with a more suitable glob
pattern).

The only reason I answered the FAQ at all was to explain how one can
devise his own solutions, instead of pestering the net for help.

 
 
 

How to rename a lot of files into lower case?

Post by Rahul Dhe » Wed, 11 Sep 1991 08:54:32



Quote:>I was answering the original request, where all the filenames WERE
>completely upper case.

Well...so long as we are splitting hairs, let me split some too:

(a) It was not guaranteed that all filenames were completely uppercase,
just that names of files transferred from MS-DOS were uppercase.  There
was no clear statement that there were no other files already in the
current directory.

(b) Even if all filenames were in uppercase, it was not a good idea to
propose a too-specific solution that could prove dangerous when applied
to a more general case.  Accidental silent deletion of files is
dangerous!
--

UUCP:  oliveb!cirrusl!dhesi
"You're even nuttier than we've come to expect of you." -- Doug Gwyn

 
 
 

How to rename a lot of files into lower case?

Post by Leslie Mikese » Thu, 12 Sep 1991 02:23:53



>>I was answering the original request, where all the filenames WERE
>>completely upper case.

>Well...so long as we are splitting hairs, let me split some too:

You missed a chance to mention yet another way to avoid the problem:
Use zoo under DOS to bundle the files for the move to unix where
zoo will extract with lowercase names automatically.  Very handy.
The reverse is nice too for the times you want to preserve the
unix filenames even though you store or move the files on MSDOS
media.  If it just maintained uid/gid and links, zoo might be the
archive of choice now that cpio has been gratituously broken in
SysVr4.

Les Mikesell

 
 
 

How to rename a lot of files into lower case?

Post by Doug Gw » Thu, 12 Sep 1991 14:50:23




>>I was answering the original request, where all the filenames WERE
>>completely upper case.
>Well...so long as we are splitting hairs, let me split some too:
>(a) It was not guaranteed that all filenames were completely uppercase,
>just that names of files transferred from MS-DOS were uppercase.  There
>was no clear statement that there were no other files already in the
>current directory.
>(b) Even if all filenames were in uppercase, it was not a good idea to
>propose a too-specific solution that could prove dangerous when applied
>to a more general case.  Accidental silent deletion of files is
>dangerous!

Again, as you omitted in the quote, my main point was to explain HOW one
goes about figuring out solutions for oneself.  Since there was not a
complete, detailed specification given, for tutorial purposes I
concentrated on the essential aspects of the technical problem.  Note
that your attempted solution enforces some assumptions that are not
necessarily any more correct than mine; for example, what makes you
think that the attempt to upload FOO.C is not SUPPOSED to overwrite
any preexisting file "foo.c"?  I'm not saying you're wrong, but you
aren't necessarily right either, and your nitpicking may distract from
the tutorial purpose of my original article.
 
 
 

How to rename a lot of files into lower case?

Post by Jan B. Anders » Thu, 12 Sep 1991 04:37:23



>Indeed this is a frequently asked question.  What puzzles me is why people
>can't figure out a solution on their own.  Here is how one would go about
>analyzing the situation:

[a description of the top-down method of creating a little shell utility]

The problem is that they don't know which tools (find,tr,echo) are available.
It was only recently that I learned of the 'apropos' and 'man -k' facility,
which are great for finding which tool to use for which task:

  $ man -k files
  find (1)                - find files by name, or by other characteristics
  $ man -k
  tr (1V)                 - translate characters

(Okay, I cheated :-) One often has to try different keywords, but that can
also be very educational!)
--

 
 
 

How to rename a lot of files into lower case?

Post by Rahul Dhe » Sat, 14 Sep 1991 08:31:09



Quote:>...my main point was to explain HOW one
>goes about figuring out solutions for oneself.

One way of quickly sketching a partial solution for tutorial purposes
is to provide one that does little or no error-checking (which you
did), and then add a warning (which you didn't), e.g., "Note that this
tutorial example may silently delete existing files if case-folding
causes a filename conflict.  Add checks as needed."

Sorry about not quoting everything you said.  If I did that, and if you
did the same, each article posted by either of us would include all our
previous articles, and that would be a horrible example to set for all
the new Usenet users out there.

Feel free to have the last word.
--

UUCP:  oliveb!cirrusl!dhesi
"When you've won the argument, let the other person have the last word." -- me

 
 
 

1. renaming files from upper case to lower case

I use file names which are all lower case. When I ftp files
from another system, often the file names are all uppercase.
How can I rename (move) all files in a directory from uppercase
to lowercase.

For example, FILE.F should be moved to file.f . Please email
me your reply if you respond to the newsgroup. Thank you.
______________________________________
Vivek Rao                            

http://www-ceg.ceg.uiuc.edu/~vrao/
Univ. of Illinois, Physics Department
1110 W Green St / Urbana IL 61801
______________________________________

2. ISDN and Linux

3. Renaming whole directory trees from upper case to lower case

4. make kernel problem!!

5. command to rename files to lower case

6. new disk in sunblade 100

7. massive renaming of the files to lower case

8. U34F,Toshiba 3401B & Linux

9. Renaming files~(from upper to lower case)

10. Change upper case file names into lower case

11. command to convert upper case to lower case in file names

12. upper case vs lower case ****newbie*****

13. lower case <-> upper case