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 ]
|