renaming lots of files

renaming lots of files

Post by Nancy La » Fri, 06 Aug 1999 04:00:00



Hi.

I need to rename lots of files in one of my directories.   I would like
to move all the files ending in .f to .F
I tried futilely to do
mv *.f *.F
but it doesn't work.  I am working on a Linux system, but I don't think
that is what is causing the "problem" - I probably just don't have the
right command.   Is there a way to move multiple files like this?   What
command would I have to type?

Thanks for your help.

 
 
 

renaming lots of files

Post by Warren Porte » Fri, 06 Aug 1999 04:00:00



>Hi.

>I need to rename lots of files in one of my directories.   I would like
>to move all the files ending in .f to .F
>I tried futilely to do
>mv *.f *.F
>but it doesn't work.  I am working on a Linux system, but I don't think
>that is what is causing the "problem" - I probably just don't have the
>right command.   Is there a way to move multiple files like this?   What
>command would I have to type?

for i in *.f; do mv $i `basename $i .f`.F ; done

should do it.  The character in front of _basename_ and after the _f_ is a
backtic, above the tab key on many keyboards and forces basename to be
evaluated before the _mv_ is done.

HTH

BTW, practice with _echo_ in front of _mv_ before doing it for real.

 
 
 

renaming lots of files

Post by Kenneth C Stah » Sat, 07 Aug 1999 04:00:00


#!/bin/ksh
for i in `find /mydir -name \*.f -print`;do
    fname=${i%%\.*};
    mv "$i" ${fname}.F";
    if [ $? -ne 0 ];then
        print -u2 "Error while renaming ${i} to ${fname}.F";
        exit 1;
    fi
done;

> Hi.

> I need to rename lots of files in one of my directories.   I would like
> to move all the files ending in .f to .F
> I tried futilely to do
> mv *.f *.F
> but it doesn't work.  I am working on a Linux system, but I don't think
> that is what is causing the "problem" - I probably just don't have the
> right command.   Is there a way to move multiple files like this?   What
> command would I have to type?

> Thanks for your help.

 
 
 

renaming lots of files

Post by Tom Kralidi » Sat, 07 Aug 1999 04:00:00


Try the following script:

#!/bin/csh

foreach i (*.f)
mv "$i" "$i:r.F"
end

Or, if you have Perl:

#!/public/bin/perl -w

foreach $small_f (<*.f>)
{
  $big_f = $small_f;
  $big_f=~ s/\..+$//;
  $big_f = $big_if . ".F";
  $old = $small_f;
  rename $small_f, $big_f;
  print "$old changed to $big_f\n";

Quote:}

print "Done\n";

Hope this helps.

..Tom


> Hi.

> I need to rename lots of files in one of my directories.   I would like
> to move all the files ending in .f to .F
> I tried futilely to do
> mv *.f *.F
> but it doesn't work.  I am working on a Linux system, but I don't think
> that is what is causing the "problem" - I probably just don't have the
> right command.   Is there a way to move multiple files like this?   What
> command would I have to type?

> Thanks for your help.

--

-----------------------------------------------------------------------------------------
Tom Kralidis                                  Geo-Spatial Technologist
Canada Centre for Remote Sensing              Tel: (613) 947-1828
588 Booth Street , Room 241                   Fax: (613) 947-1408
Ottawa , Ontario K1A 0Y7                     http://www.ccrs.nrcan.gc.ca
-----------------------------------------------------------------------------------------

 
 
 

1. renaming lots of files

:I need to change the case of about 1200 filenames (lower to upper), I am
:currently trying to figure out how to do it with awk or sed,
:but with no luck.  Any suggestions are greatly appreciated!

if the list of files is in a file, one per line:

while read lower
do
upper=`echo $lower | tr 'abcdefghijklmnopqrstuvwxyz' \
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
/bin/mv $lower $upper
done < list_of_the_files

or if there aren't too many to use 'ls whatever.*':

for f in `ls whatever.*`
do
...
done

--
tim butler

2. root cron problem after 4.2.1 -> 4.3.2 upgrade

3. Renaming lots of files

4. Course: Using Linux in Embedded Systems

5. newbie need to rename lots of files

6. T1 or 56K interface for linux?

7. Renaming lots of files

8. Making KDE work for a non root user and succeding ::)) for newbies

9. How to rename a lot of files into lower case?

10. Renaming a lot of similarly named files

11. How to rename a lot of files ?

12. Help using awk and bash script to copy and rename lots of index.htm files

13. consistent read() on file while rename() file.new -> file?