Solved

Renaming several files at once

Posted on 1998-06-24
8
307 Views
Last Modified: 2011-08-18
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..
0
Comment
Question by:moonlight
  • 4
  • 3
8 Comments
 
LVL 3

Author Comment

by:moonlight
ID: 2008247
Edited text of question
0
 

Accepted Solution

by:
rayray120497 earned 0 total points
ID: 2008248
try this:

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

0
 

Expert Comment

by:rayray120497
ID: 2008249

also try this:

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

0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Expert Comment

by:rayray120497
ID: 2008250

sorry, should be

mv $i $j.org
0
 
LVL 3

Author Comment

by:moonlight
ID: 2008251
The first batch didnt work, somehow just one file gets renamed,
but the second did what I wanted, thanx!!
0
 
LVL 3

Author Comment

by:moonlight
ID: 2008252
First one works too now..excellent, thanks again rayray
0
 
LVL 84

Expert Comment

by:ozo
ID: 2008253
 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
 
LVL 3

Author Comment

by:moonlight
ID: 2008254
thx, ozo.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question