On Thu, Jul 24, 2014 at 07:09:17AM -0700, jpwalker@fastmail.fm [LINUX_Newbies] wrote:
> I have several different sets of photos that all have them same numbers. I would like to rename them as- 1- 100A, or 1-100B for example. How can I do this from the command line?
Assuming you have them in a directory called photos, while in that
directory
First test it.
for i in *.jpg;do echo mv "$i" "${i%%.jpg}" A.jpg;done
This will show you what it would do. For example,in a directory that has
two pictures, 1.jpg and 2.jpg I ran the command and get
for i in *.jpg; do echo mv "$i" "${i%%.jpg}"A.jpg;done
mv 1.jpg 1A.jpg
mv 2.jpg 2A.jpg
Once you've tested it by using echo you can now it for real.
for i in *.jpg;do mv "$i" "${i%%.jpg}" A.jpg;done
In this case, what we're doing is what's called a for loop, (because it
uses the word for, as opposed to a while loop). for i in *.jpg means for a
a variable, which we're callling i, in a group, in this case, any file
ending with .jpg, move, (in this case, that means rename) the file. The
${i%% means that we're going to get rid of whatever comes after the %%, in
this case, .jpg, then outside of the bracket, put in a letter A and put the
.jpg back. There are other ways and scripts, but that is one of the
simpler methods, IMHO.
--
Scott Robbins
PGP keyID EB3467D6
( 1B48 077D 66F6 9DB0 FDC2 A409 FA54 EB34 67D6 )
gpg --keyserver pgp.mit.edu --recv-keys EB3467D6
To unsubscribe from this list, please email LINUX_Newbies-unsubscribe@yahoogroups.com & you will be removed.