Renaming files

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.






PapsniperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arthurdCommented:
#!/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
ahoffmannCommented:
ls * | awk -F. '{print "mv "$0" /accounts/today/"$1".abc";}' |sh
0
PapsniperAuthor Commented:
pl check to see that the problem is different.

Pap.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

PapsniperAuthor Commented:
Hi ,
could anybody answer my question which has got the title
'renaming files'.

Thanks,
Pap.


0
arthurdCommented:
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
bard081298Commented:
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
alextrCommented:
What is wrong with two above solution? They work fine for your problem. If your problem is different, please explain it better!!
0
ozoCommented:
The only real difference I see between the question and the answers is
ls cs*.bakup*.1999*
0
ahoffmannCommented:
according to ozo's comment

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ahoffmannCommented:
.. 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
arthurdCommented:
whatever
0
PapsniperAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.