  Linear codes with a few weights have been widely investigated in recent
years. In this paper, we mainly use Gauss sums to represent the Hamming weights
of a class of $q$-ary linear codes under some certain conditions, where $q$ is
a power of a prime. The lower bound of its minimum Hamming distance is
obtained. In some special cases, we evaluate the weight distributions of the
linear codes by semi-primitive Gauss sums and obtain some one-weight,
two-weight linear codes. It is quite interesting that we find new optimal codes
achieving some bounds on linear codes. The linear codes in this paper can be
used in secret sharing schemes, authentication codes and data storage systems.
