by looking at the spectra, you can tell that they are moving away because all those dark lines, which are produced by chemical elements in the atmospheres of stars, showed the same pattern, but that pattern was shifted to longer wavelengths, redder wavelengths, as though the things were moving away from us.