You may want to add -F 4 to remove unmapped reads, and -h to keep the headers so that SAM/BAM viewers can read that file. The command I use (removes also reverse complements) is :
samtools view -h -F 4 -F 16 -F 256 alignments.sam | grep -E "@|NM" | grep -v "XS:" > uniq_noRev.sam
However this command screws up a bit, because the lines with "XS" are removed, while their corresponding headers remain on top of the file.
First what aligner you used?
There are two posts first here will discuss what is sam flag meaning
SAM flags meaning
and the second here about filtering sam
How To Filter Mapped Reads With Samtools
SAM and BAM filtering oneliners
It is better to filter based on MAPQ (map quality)