You have 2 ways to do that, depending on whether you want to keep the bootloader or not.
If you don't care about keeping the bootloader, you need to have a ISP programmer (such as USBasp, AVRISP or even another arduino). You'll connect the ISP programmer to the ICSP header on your arduino.
If you need/want to keep the bootloader, you may use the serial port as you are already doing. You'll just have to replicate on a command prompt (or shell) the same avrdude command that the IDE is issuing. If you have the verbose upload feature of the IDE turned on, you can see the avrdude command the IDE uses to upload the sketch's .HEX file.
Either way, you'll use a command promp (or shell) and you'll be using avrdude directly.