rename multiple files in multiple directories
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > rename multiple files in multiple directories




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    rename multiple files in multiple directories  
p@p.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-30-07 12:23 AM

All,

I have a sol 10 server running samba and I have a varied directory structure
under /data that has loads of sub dir's with loads of *.gho files scattered
in this structure.

I need a script to find any  "*.gho" files and change them to "*.aaa.gho"
files, I have managed to find/try the following with limited success

for f in *.gho ; do mv $f `basename $f gho`v0.1.gho; done
This does rename and gho files, but only does it for the PWD, while (how can
I repeat this for every sub dir ?)

find * - type f -print | grep gho
finds all gho files in all sub dirs ( how can I then rename every gho file
it finds ?).

Somehow I need to stitch the two together, your help is appreciated.....

(I do not want to use perl, I'm after as simple(for me to understand) as
possible script)


Thanks

again

Paul







[ Post a follow-up to this message ]



    Re: rename multiple files in multiple directories  
Xicheng Jia


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-30-07 12:23 AM

On Jan 29, 4:09 pm, "p...@p.com" <P...@p.com> wrote:
> All,
>
> I have a sol 10 server running samba and I have a varied directory structu
re
> under /data that has loads of sub dir's with loads of *.gho files scattere
d
> in this structure.
>
> I need a script to find any  "*.gho" files and change them to "*.aaa.gho"
> files, I have managed to find/try the following with limited success
>
> for f in *.gho ; do mv $f `basename $f gho`v0.1.gho; done
> This does rename and gho files, but only does it for the PWD, while (how c
an
> I repeat this for every sub dir ?)
>
> find * - type f -print | grep gho
> finds all gho files in all sub dirs ( how can I then rename every gho file
> it finds ?).
>
> Somehow I need to stitch the two together, your help is appreciated.....
>

Under bash (dont know if it works under sol 10 though):

find * -type f -name "*.gho" -print | while IFS=; read -r f; do mv
"$f" "${f%.gho}.aaa.gho"; done

(assumed no newline in filenames)

Regards,
Xicheng






[ Post a follow-up to this message ]



    Re: rename multiple files in multiple directories  
p@p.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-30-07 12:23 AM

Xicheng Thanks,

Just tested it and thats perfect, thank you, I would like to understand it a
bit more though...

Regards
Paul

"Xicheng Jia" <xicheng@gmail.com> wrote in message
news:1170109761.637408.164200@a75g2000cwd.googlegroups.com...
> On Jan 29, 4:09 pm, "p...@p.com" <P...@p.com> wrote: 
>
> Under bash (dont know if it works under sol 10 though):
>
>  find * -type f -name "*.gho" -print | while IFS=; read -r f; do mv
> "$f" "${f%.gho}.aaa.gho"; done
>
> (assumed no newline in filenames)
>
> Regards,
> Xicheng
>







[ Post a follow-up to this message ]



    Re: rename multiple files in multiple directories  
Steffen Schuler


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-30-07 12:23 AM

p@p.com wrote:
> All,
>
> I have a sol 10 server running samba and I have a varied directory structu
re
> under /data that has loads of sub dir's with loads of *.gho files scattere
d
> in this structure.
>
> I need a script to find any  "*.gho" files and change them to "*.aaa.gho"
> files, I have managed to find/try the following with limited success
>
> for f in *.gho ; do mv $f `basename $f gho`v0.1.gho; done
> This does rename and gho files, but only does it for the PWD, while (how c
an
> I repeat this for every sub dir ?)
>
> find * - type f -print | grep gho
> finds all gho files in all sub dirs ( how can I then rename every gho file
> it finds ?).
>
> Somehow I need to stitch the two together, your help is appreciated.....
>
> (I do not want to use perl, I'm after as simple(for me to understand) as
> possible script)
>
>
> Thanks
>
> again
>
> Paul
>
>
with GNU toolchain:

find * -type f -name "*.gho" -print0 |
xargs -r0 -I {} bash -c 'f="{}"; mv "$f" "${f%gho}aaa.gho"'


This works also for newlines and other whitespace in your filenames.
It's tested.

Instead of an explanation, look for:

info find
man 1 xargs
man 1 bash

Enjoy,

Steffen





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:19 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register