Renaming several files at once

I would like to append a .org extension to some files in a directory,
e.g. renaming all files ending with .cc to .cc.org
Now, how can I do that without having to do a :
mv xxx.cc xxx.cc.org  on every file ?
also:
How substitute xxx.cc with xxx.org ?
Im seeking a command+arguments or a minor sh script..
LVL 3
moonlightAsked:
Who is Participating?
 
rayray120497Connect With a Mentor Commented:
try this:

foreach i ( `ls *.cc` )
mv $i $i.org
end

0
 
moonlightAuthor Commented:
Edited text of question
0
 
rayray120497Commented:

also try this:

foreach i (`ls *.cc` )
set j = `expr $i : '\(.*\).cc'`
mv $i $j
end

0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
rayray120497Commented:

sorry, should be

mv $i $j.org
0
 
moonlightAuthor Commented:
The first batch didnt work, somehow just one file gets renamed,
but the second did what I wanted, thanx!!
0
 
moonlightAuthor Commented:
First one works too now..excellent, thanks again rayray
0
 
ozoCommented:
 foreach i ( `ls *.cc` )
could be just
  foreach i ( *.cc )

but that's actually a csh command.  
in sh, it would be
  for i in `ls *.cc` ; do
     mv $i $i.org
  done
0
 
moonlightAuthor Commented:
thx, ozo.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.