  The study of cosmology, galaxy formation and exoplanets has now advanced to a
stage where a cosmic inventory of terrestrial planets may be attempted. By
coupling semi-analytic models of galaxy formation to a recipe that relates the
occurrence of planets to the mass and metallicity of their host stars, we trace
the population of terrestrial planets around both solar-mass (FGK type) and
lower-mass (M dwarf) stars throughout all of cosmic history. We find that the
mean age of terrestrial planets in the local Universe is $7\pm{}1$ Gyr for FGK
hosts and $8\pm{}1$ Gyr for M dwarfs. We estimate that hot Jupiters have
depleted the population of terrestrial planets around FGK stars by no more than
$\approx 10\%$, and that only $\approx 10\%$ of the terrestrial planets at the
current epoch are orbiting stars in a metallicity range for which such planets
have yet to be confirmed. The typical terrestrial planet in the local Universe
is located in a spheroid-dominated galaxy with a total stellar mass comparable
to that of the Milky Way. When looking at the inventory of planets throughout
the whole observable Universe, we argue for a total of $\approx 1\times
10^{19}$ and $\approx 5\times 10^{20}$ terrestrial planets around FGK and M
stars, respectively. Due to light travel time effects, the terrestrial planets
on our past light cone exhibit a mean age of just $1.7\pm 0.2$ Gyr. These
results are discussed in the context of cosmic habitability, the Copernican
principle and searches for extraterrestrial intelligence at cosmological
distances.
