[NTLUG:Discuss] batch copy and rename
Kevin Brannen
kbrannen at pwhome.com
Wed Jun 23 23:37:12 CDT 2004
Bobby Wrenn wrote:
> I have a bunch of JPGs from our vacation. The camera starts its number
> sequence over each time you erase the Compact Flash. So, I sorted the
> files into directories for each date. The directories have the date as
> their names (eg 6-13-04, 6-14-04, etc.). I want to each file to a new
> single directory and prepend the date to the file name at the same time.
>
> I know find and xargs are my friends. But, I'm not even good enough to
> be dangerous as at shell scripting. Any help greatly appreciated.
>
> TIA
> Bobby
Assume you have:
./pict/
6-13-04/
6-14-04/
....
Try:
---
#!/bin/ksh
dest=/tmp/pict_all
[ -d $dest ] || mkdir $dest
# assume you are sitting in "pict"
# change to "jpg" if needed
find . -name "*.JPG" -print |
while read f
do
new=$(echo $f | sed -e 's=^\./==' -e 's=/=_=g')
cp $f $dest/$new
done
---
This is untested!!! Try changing the "cp" to "echo cp" to see that it's
doing the right thing before you run it for real (without the echo).
Feel free to change the "cp" to "mv".
HTH,
Kevin
More information about the Discuss
mailing list