In this paper, we classify all optimal linear codes over up to length , and determine the number of optimal codes which are self-dual and formally self-dual. Optimal codes with linear binary images are identified. In particular, we show that for length , there are nine optimal codes for the Hamming distance, one optimal code for the Lee distance, and two optimal codes for the Euclidean distance.