How to rotate a set of pictures from the command line?

You can use the convert command:

convert input.jpg -rotate angle in degreed out.jpg

To rotate 90 degrees clockwise:

convert input.jpg -rotate 90 out.jpg

To save the file with the same name:

convert file.jpg -rotate 90 file.jpg

To rotate all files:

for photo in *.jpg ; do convert $photo -rotate 90 $photo ; done

Alternatively, you can also use the mogrify command line tools (the best tool) recommended by @don-crissti:

mogrify -rotate 90 *.jpg

For JPEG images and right-angle rotations, use jpegtran or exiftran, as they can rotate the images losslessly.

for f in *.jpg ; do 
    jpegtran -rotate 180 "$f" > "${f%.jpg}-rotated.jpg"
done

Or to rotate in-place:

for f in *.jpg ; do
    jpegtran -rotate 180 -outfile "$f" "$f"
done

exiftran also has the -a flag to automatically rotate the image based on what the EXIF orientation tag says.