It helps to know which package provides the command. For example, on many (but not all!) Linux distributions, the ls command is provided by the GNU coreutils package. You can find the sources for those commands by following links from the coreutils web page.
The ping command is provided by the iputils package; you can find the souces here.
Most distributions provide a mechanism for figuring out what package owns a file. For example, on Ubuntu, we can use dpkg-query, like this:
$ dpkg-query -S /bin/ls
coreutils: /bin/ls
The corresponding command for Red Hat/Fedora/CentOS/etc is:
$ rpm -qf /bin/ls
coreutils-8.32-33.fc35.x86_64
If you know the package that provides the files in which you are interested, you can often find the sources by looking for the corresponding source package provided by your distribution. For Ubuntu, you can go to https://packages.ubuntu.com/ and look up packages by name; if you search for iputils, you would end up here, and you will find links to download the sources used to build that package.
For Fedora packages, you can go to https://packages.fedoraproject.org/ and search for the package. In this case, you would need to read the spec file (e.g., this one for iputils) to figure out where to find the sources.
If you are using something other than Ubuntu or Fedora, there will probably be a similar mechanism available. Most distributions also provide command line tooling for downloading the source packages by name.