With a delivered integrated luminosity of around 140 fb$^{-1}$ at a center-of-mass energy of 13 TeV in the CMS experiment during Run 2, almost 300 million top quarks and top antiquarks were produced.
As top quarks can be produced through either strong or electroweak interaction, they are a suitable tool to probe the strong and electroweak sectors of the standard model.
Precision measurements of top quark pair ($\text{t}\bar{\text{t}}$) and of single top quark production cross sections deliver constraints on several standard model parameters, e. g., the top quark mass, the strong coupling $\alpha_S$, and the parton distribution functions.
In addition, a sufficient amount of data has been collected to search for rare $\text{t}\bar{\text{t}}$ production modes.
In this contribution, recent measurements of the differential $\text{t}\bar{\text{t}}$ cross sections and the latest inclusive and differential cross section measurement for single top quark production in association with a W boson performed by the CMS Collaboration are presented, as well as the search for exclusive $\text{t}\bar{\text{t}}$ production using the CMS-TOTEM Proton Precision Spectrometer.