operating-systemwcutilities

How to find the source of the wc.c?


The wc command is often touted as the fastest way to count the number of lines in a file, https://unix.stackexchange.com/questions/504892/what-is-a-quick-way-to-count-lines-in-a-4tb-file

When I tried to look for the source code of wc.c that let uses do something like wc -l or wc -c, I've found the code from https://www.gnu.org/software/cflow/manual/html_node/Source-of-wc-command.html but


Solution

  • Tracking a specific binary source for a specific distro:

    1. find the binary:

      $ which wc
      /usr/bin/wc
      
    2. find the package that provided the binary

      $ dnf whatprovides /usr/bin/wc
      <or>
      $ yum whatprovides /usr/bin/wc
      <or>
      $ dpkg -S /usr/bin/wc
      
      coreutils-8.30-13.el8.x86_64
      
    3. Google the package with "src" to find the src package used to build specifically the package that you have.

      In the above example its: http://vault.centos.org/8-stream/BaseOS/Source/SPackages/coreutils-8.30-13.el8.src.rpm

    4. Download the src package and unpack it to reveal the actual source used to build wc in your distro

    5. Compare it to the official wc.c in coreutil's github: https://github.com/coreutils/coreutils/tree/master/src