0

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

  • Q (part a): Is this the actual source code for the wc command?
  • Q (part b): Is there some mirror on github / gitlab / bitbucket for the code?
  • Q (part c): If the wc.c file is different for different unix versions, how do file the source of the wc.c? When I tried which wc, it only points me to the binary.
Jean-Baptiste Yunès
  • 34,548
  • 4
  • 48
  • 69
alvas
  • 115,346
  • 109
  • 446
  • 738
  • 1
    `wc` on Linux probably comes from the GNU coreutils package (as you can find from inspecting the man page), [here](https://www.gnu.org/software/coreutils/#source). Busybox may have its own implementation, as very likely will other Unices. Neither UNIX command-line utilities nor Google-fu are C++ questions. – Useless Nov 04 '22 at 11:00
  • Find which OS you are using, if it is an open source OS, it will be easy to find the right sources. Whatever, all implementations of it are almost the same, take one (GNU for example) and look at it. – Jean-Baptiste Yunès Nov 04 '22 at 11:45

1 Answers1

3

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

Shloim
  • 5,281
  • 21
  • 36