We derive a discrete framework for the calculation of eigenvalue sensitivity to geometric deformations. We apply the technique to the steady compressible Navier-Stokes and Reynolds-averaged Navier-Stokes (RANS) flows. The analysis enables one to control (reduce or increase) the amplification rate or frequency associated to the least stable global mode, which is identified using stability analysis. A methodology using a discrete framework is proposed, allowing one to recover the gradients in compressible and turbulent flows. The potential of the resulting shape gradients is evaluated on the well-known circular cylinder flow problem and on a RANS turbulent flow scenario to control the buffet onset on a NACA0012 airfoil. The predicted deformations show excellent performance on the stabilization or excitation, and frequency control, of the global modes and for the two cases tested.