Solved

Renaming several files at once

Posted on 1998-06-24
8
308 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

830 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