Only sometimes, I forget to make a backup of a given linux file such as
/etc/dhcpcd.conf, etc, and later wish I did. Distribution agnostic, is there a good approach to later getting a copy of an unf'd up copy?
While the topic of configuration files backup/versioning might seem simple on the surface, it is one of the hot topics of system/infrastructure administration.
Distribution agnostic, to keep automatic backups of /etc as a simple solution you can install etckeeper.
By default it commits /etc to a repository/version control system installed on the same system.
The commits/backups are by default daily and/or each time there are package updates.
The etckeeper package is pretty much present in all Linux distributions.
It could be argued it is a good standard of the industry to have this package installed.
If you have not etckeeper installed, and need a particular etc file, there are several ways; you might copy it from a similar system of yours, you can ask your package manager to download the installation file or download it by hand, and extract the etc file from there; one of the easiest ways is using mc (midnight commander) to navigate inside packages as if they were directories.
You can also use the distribution repositories to get packages, in the case of debian is http://packages.debian.org
Ultimately if the etc/configurations are mangled beyond recognition you always have the option to reinstall the particular package. move the etc files to a backup name/directory, and for instance in Debian:
apt-get install --reinstall package_name
You can also configure and install the source repos for your particular distribution/version, install the source package, and get the etc files from there.
https://wiki.debian.org/apt-src (again a Debian example)
In some packages, you might also have samples of the configurations files at /usr/share/doc/package_name, which might be fit or not for use.
As a last resort, you may also find etc files in the repositories/github addresses if the corresponding open source projects, just bear in mind that often distributions change default settings and things around.
Obviously, none of these alternatives exempt you from having a sound backup policy in place, and retrieve your lost /etc files from there.
Times also move fast, and if following a devops philosophy, you might also choose to discard certains systems altogether and redeploy them in case some files get corrupted; you might also use CI and reploy the files for instance, from jenkins.
If your distribution has a live ISO, or you don't mind doing a virtual install to a Virtual Machine (VirtualBox, VMWare, etc) then you could see it's default files without digging through package files manually.
And installing / re-installing / re-configuring any packages in the VM wouldn't change your "real" system files.