Situation, I have a bunch of pictures:
1503.jpg
1504.jpg
1505.jpg
etc...
I want to rename all of them at once to, for example:
1.jpg
2.jpg
3.jpg
Make a script like this:
<script>
#!/bin/bash
#
# Moves jpeg files from one folder, to a new folder, and renames them numericly
#
if [ "$1" == "" ]
then
echo "Usage: numberfiles old-dir new-dir
exit 0
fi
if [ "$2" == "" ]
then
echo "Usage: numberfiles old-dir new-dir
exit 0
fi
NUMBER=0
echo "Moving files in $1 to $2 and renaming them numericly"
cd $1
for i in `ls *.[jJ][pP][gG]`;
do mv "$i" "$2/$NUMBER.jpg" && NUMBER=`expr $NUMBER + 1`;
done
</script>
Make it executable and run it.
The script goes like this:
./scriptname /path/to/from/directory /path/to/to/directory
It will move all the JPG/jpg files from the from directory to the to
directory, while renaming them numericly, starting at 0. I was using a
script very similar to this earlier today, so I just modified my
script.
I haven't run this exact script though, so make a backup of your files
before using it. My original script almost lost some of my files,
because it wrote over the top of some other file. eg. There was
already a file named "20.jpg" and it moved some other file to have
that same name, losing 20.jpg.
hth,
--
Michael Moore
--------------------
BYU Unix Users Group
http://uug.byu.edu/
The opinions expressed in this message are the responsibility of their
author. They are not endorsed by BYU, the BYU CS Department or BYU-UUG.
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list