samtools(1) view -b my_sample.sam -o my_sample.sam
Utilities for the Sequence Alignment/Map (SAM) format
-b      Output in the BAM format.
-o FILE Output file [stdout]
source manpages: samtools