Optimal control problems with an $ L^0 $ term in the cost functional are considered. The $ L^0 $ term measures the size of the support of the control, and brings difficulty for studying the optimal control problems. By studying the existence and necessary conditions of optimal controls for a series of approximation problems and corresponding relaxed problems, the existence of optimal controls for a controlled elliptic system with an $ L^0 $-cost is obtained. Necessary conditions and the $ L^\infty $-regularity of optimal controls are showed in the paper as well.