CONVERTING lower-case to upper-case filenames?

CONVERTING lower-case to upper-case filenames?

Post by Mark A. Pitch » Tue, 15 Nov 1994 02:46:44



        I'm transfering >50 megs of files from my flakey DOS machine to my
Linux machine over a serial line using zmodem. The flakey DOS machine crashes
every so often, so I need to use the crash-recovery features of zmodem.

        Unfortunately, DSZ on the DOS machine only sends upper-case
filenames, while RZ on the Linux machine writes lower-case filenames.
This means that when DSZ checks to see what files are already written, it
only looks for upper-case filenames, and because it doesn't see anything
it re-writes the files that were uploaded previously.

        I imagine that there's a way to rename all of the files on the Linux
machine (about 1000 of them) using a script. Anyone know how to do this?
"sed" seems like the proper tool, but I can't find any good
documentation on it.

        Much thanks to anyone who can help.

--
------------------------------------------------------------------------------
| Mark A. Pitcher |                                
------------------------------------------------------------------------------
                                                            "GUH!" - Bill Leeb

 
 
 

CONVERTING lower-case to upper-case filenames?

Post by J.J. Paijma » Tue, 15 Nov 1994 22:44:48



...

Quote:

>    I imagine that there's a way to rename all of the files on the Linux
>machine (about 1000 of them) using a script. Anyone know how to do this?
>"sed" seems like the proper tool, but I can't find any good
>documentation on it.

>    Much thanks to anyone who can help.

There is an alternative for 'mv', called 'mmv'. It does regular expression-like
operations on filenames. On sunsite.unc.edu. somewhere.

Hope this helps.

[paai

XS

 
 
 

CONVERTING lower-case to upper-case filenames?

Post by Richard Hi » Tue, 15 Nov 1994 04:35:33




Quote:>    I imagine that there's a way to rename all of the files on the Linux
>machine (about 1000 of them) using a script. Anyone know how to do this?

for i in `find .`; do j=`echo $i | tr [a-z] [A-Z]`; mv $i $j; done

Anybody know a better way?

 
 
 

CONVERTING lower-case to upper-case filenames?

Post by Andreas Kostyrka ( yac » Thu, 17 Nov 1994 22:21:57



: ...

: >
: >  I imagine that there's a way to rename all of the files on the Linux
: >machine (about 1000 of them) using a script. Anyone know how to do this?
: >"sed" seems like the proper tool, but I can't find any good
: >documentation on it.
: >
: >  Much thanks to anyone who can help.
: >

: There is an alternative for 'mv', called 'mmv'. It does regular expression-like
: operations on filenames. On sunsite.unc.edu. somewhere.

Or one can do following:
for i in myfiles ; do mv $i `echo $i | tr 'abc..xyz' 'ABC..XYZ'` ; done

Just a quick and dirty fix, but for such trivial ones, you don't need to
download anything.

Another one:
Q: Removing '.x' extensions from all files in the current directory:
A: for i in * ; do mv $i `echo $i | sed 's/.x$//'` ; done

Oh, I almost forgot to say, that this ``oneliners'' work only with Bourne
shell style shells. (e.g.: BASH)

: Hope this helps.

: [paai

: XS

 
 
 

CONVERTING lower-case to upper-case filenames?

Post by Dion Hollenbe » Wed, 23 Nov 1994 06:50:41




Quote:>> I imagine that there's a way to rename all of the files on the Linux
>> machine (about 1000 of them) using a script. Anyone know how to do this?

Richard> for i in `find .`; do j=`echo $i | tr [a-z] [A-Z]`; mv $i $j; done

Richard> Anybody know a better way?

Yes.  Unfortunately it seems that you may not have tried your method.
While on some UNIX systems it may work, it is not portable because of
the way that find traverses the directory structure.  I tried this in
the beginning, but it would not work.  What you need to do is go down
the directory tree once and change all the names of the direcories,
one at a time from the bottom up.  Then go back down the tree and
change filenames.  If you go to the top and change a directory name,
then when find uses it's cached version of the directory name, it no
longer exists in the filesystem.

Here are scripts to do it.  Unfortunately, it has to be complicated,
or it will not work.  I wish your simple form would have worked for
me.

Run lcasedirs first, then run lcasefiles.

--------------------------------------------------------------------------
#!/bin/sh
#
#       lcasefiles
#
#  script to lowercase files in a directory tree
#

LCASEFILES="/tmp/lcase.files.$$"

cat <<'EOF' > $LCASEFILES
#!/bin/sh
if [ $# -lt 1 ]
then
        echo No file specified in $0
        exit 1
fi
FILE="$1"
BASE=`basename $FILE`
PARDIR=`dirname $FILE`
LFILE=`echo $BASE | tr A-Z a-z`

if [ ! "$FILE" = "$PARDIR/$LFILE" ] ; then
#       echo mv $FILE $PARDIR/$LFILE
        mv $FILE $PARDIR/$LFILE
        chmod -x $PARDIR/$LFILE
        ls -l $PARDIR/$LFILE
#else
#       echo $FILE and $PARDIR/$LFILE are the same
fi
exit 0

EOF

chmod +x $LCASEFILES

find . -type f -exec $LCASEFILES {} \;

rm $LCASEFILES
--------------------------------------------------------------------------

#!/bin/sh
#
#       lcasedirs
#
#       script to lowercase directory names in a tree
#

LCASEDIRS="/tmp/lcase.dirs.$$"

cat <<'EOD' > $LCASEDIRS
#!/bin/sh
if [ $# -lt 1 ]
then
        echo No directory specified in $0
        exit 1
fi
if [ "$1" = "." ] ; then
        echo skipping $1
        exit 0
fi
if [ "$1" = ".." ] ; then
        echo skipping $1
        exit 0
fi
CURDIR=`pwd`
cd $1
DIR=`pwd`
cd ..
BASE=`basename $DIR`
PARDIR=`dirname $DIR`
LDIR=`echo $BASE | tr A-Z a-z`

if [ ! "$DIR" = "$PARDIR/$LDIR" ] ; then
        echo mv $DIR $PARDIR/$LDIR
        mv $DIR $PARDIR/$LDIR
#else
#       echo $DIR adn $PARDIR/$LDIR are the same
fi
exit 0

EOD

chmod +x $LCASEDIRS

find . -depth -type d -exec $LCASEDIRS {} \;

rm $LCASEDIRS

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

--

Staff Software Engineer     Megatek Corporation, San Diego, California

 
 
 

CONVERTING lower-case to upper-case filenames?

Post by Roos van Raadshooven L. » Sun, 08 Jan 1995 13:48:01





>: ...
>: >
>: >      I imagine that there's a way to rename all of the files on the Linux
>: >machine (about 1000 of them) using a script. Anyone know how to do this?
>: >"sed" seems like the proper tool, but I can't find any good
>: >documentation on it.
>: >
>: >      Much thanks to anyone who can help.
>: >
>: There is an alternative for 'mv', called 'mmv'. It does regular expression-like
>: operations on filenames. On sunsite.unc.edu. somewhere.
>Or one can do following:
>for i in myfiles ; do mv $i `echo $i | tr 'abc..xyz' 'ABC..XYZ'` ; done

for all your disk space:

for i in `find / -print` ; do mv $i `echo $i | tr 'abc..xyz' 'ABC..XYZ'` ; done

Quote:>Just a quick and dirty fix, but for such trivial ones, you don't need to
>download anything.
>Another one:
>Q: Removing '.x' extensions from all files in the current directory:
>A: for i in * ; do mv $i `echo $i | sed 's/.x$//'` ; done
>Oh, I almost forgot to say, that this ``oneliners'' work only with Bourne
>shell style shells. (e.g.: BASH)
>: Hope this helps.
>: [paai
>: XS

 
 
 

CONVERTING lower-case to upper-case filenames?

Post by Herbert » Tue, 10 Jan 1995 18:03:36



: for all your disk space:

: for i in `find / -print` ; do mv $i `echo $i | tr 'abc..xyz' 'ABC..XYZ'` ; done

That'll really mess things up as find always puts the parent first.

--
A.  B <=> True                    B.  A <=> False


 
 
 

CONVERTING lower-case to upper-case filenames?

Post by Scott Bark » Wed, 11 Jan 1995 02:37:54




> : for all your disk space:
> : for i in `find / -print` ; do mv $i `echo $i | tr 'abc..xyz' 'ABC..XYZ'` ; done
> That'll really mess things up as find always puts the parent first.

Use the -depth option on find to force outputting children first.

--
Scott Barker

[I reply promptly to all e-mail. If you don't get a response, I didn't get]
[your mail. Check your e-mail headers before sending a reply. Your mailer ]
[should parse my address out of the From: line. If it doesn't, your e-mail]
[program is brain-damaged. * at your sysadmin to get it fixed.        ]

"The aim of a joke is not to degrade the human being, but to remind him that
   he is already degraded."
   - George Orwell

 
 
 

1. Script to Convert Upper Case Filenames to Lower Case

     Can someone suggest to me a few lines of shell script that will
convert filenames in a directory from upper case to lower case.
     Thanks in advance for any comments or suggestions.

                                -- Larry
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


Computer Consultant/Programmer                    716-685-1865-ext 550  Voice

2. Samba smbmount problem CONFIRMED by RedHat

3. Change Upper case filename to lower case filename

4. Scripts for gathering system harware configurations

5. VI - Lower-case to Upper-case

6. FAQ? sh: redirect io to/from serial port

7. Convert upper case to lower case

8. ? Best Way To Dial in to Linux From NT Workstation via Modem?

9. Converting from lower case to upper case using sed

10. Help: how to convert lower case to upper case?

11. Converting Lower Case to Upper Case

12. Convert Upper Case to Lower Case

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