As you know the jpg files made by digital camera very often are large size. If you want easily to optimize jpeg files in Ubuntu terminal, you should install jpegoptim application:
sudo apt-get install jpegoptim
Usage this app is very simple. Copy all files you want to compress/optimize to a folder and then make a command from terminal (when you are in this folder of course):
jpegoptim *.JPG --max=50
This command will change the quality of jpg files (and size of files too). Remember about correct extension of the files! *.JPG is not *.jpg (capital and small letters).