[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Renaming files

Posted on 1999-06-30
12
Medium Priority
?
367 Views
Last Modified: 2010-04-21
I have got around hundred files under a directory called
/accounts/payroll .
Now the files under the above directory look as below.

eg:cs*.bakup*.1999*

Now i have to rename all the files to cs*.abc and put
back in the same directory /accounts/today.

I used the mv command to rename for one file , but
i want to do the same , that is renaming all the files
 with one command .

the syxtax i used is  mv cs0001.bakup1.19990501 cs0001.abc
 The above command worked, but can i rename all the files
at one stretch by modifying the above command.

Thanks in advance,
Pap.






0
Comment
Question by:Papsniper
  • 3
  • 3
  • 3
  • +3
12 Comments
 
LVL 1

Expert Comment

by:arthurd
ID: 2011294
#!/bin/ksh
cd /accounts/today
ls > /tmp/filelist
exec < /tmp/filelist
while read filename
do
    first=`echo $filename | awk -F. '{print $1}'`
    mv $filename $first.abc
done
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2011295
ls * | awk -F. '{print "mv "$0" /accounts/today/"$1".abc";}' |sh
0
 

Author Comment

by:Papsniper
ID: 2011296
pl check to see that the problem is different.

Pap.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Papsniper
ID: 2011297
Hi ,
could anybody answer my question which has got the title
'renaming files'.

Thanks,
Pap.


0
 
LVL 1

Expert Comment

by:arthurd
ID: 2011298
What's wrong with the two proposed answers/comments?  Both should work.  I've re-read your question, and according to that, these should work.


0
 

Expert Comment

by:bard081298
ID: 2011299
If I understand what you are asking, you want to rename all of the files at once.  I don't think there's a tool that will do this, but the above 2 answers will certainly result in all of the files being renamed, which is the end result you want anyway.  They just do it one file at a time, which is how a utility that "renames them all at once" would do it under the covers.

Bard
0
 
LVL 1

Expert Comment

by:alextr
ID: 2011300
What is wrong with two above solution? They work fine for your problem. If your problem is different, please explain it better!!
0
 
LVL 85

Expert Comment

by:ozo
ID: 2011301
The only real difference I see between the question and the answers is
ls cs*.bakup*.1999*
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 30 total points
ID: 2011302
according to ozo's comment

ls cs*.bakup*.1999*|awk -F. '{print "mv "$0" /accounts/today/"$1".abc";}'|sh
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2011303
.. or if you want to have a simple command (alias in csh):

alias mv_all 'ls \!* |awk -F. '"'"'{print "mv "$0" /accounts/today/"$1".abc";}'"'"'|sh'

which is then to be called like:
   mv_all cs*.bakup*.1999*
0
 
LVL 1

Expert Comment

by:arthurd
ID: 2011304
whatever
0
 

Author Comment

by:Papsniper
ID: 2011305
Hi,

Your command worked.I wanted only a single line to be typed at my unix prompt which you had sent.

ls * | awk F. '{print "mv "$0" /accounts/today/"$1".abc";}' |sh

Sorry for the delay as i was away from my work.

Thanks,
Pap.


0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
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.:
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.
Suggested Courses

591 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