2

In this particular case the reset command. I want to read the code of this command.

TY

userDepth
  • 1,970
  • 2
  • 27
  • 56

1 Answers1

7

For commands that are actually present on the system, the query mode of dpkg is often helpful: either dpkg -S or (equivalently) dpkg-query -S e.g.

$ dpkg-query -S $(which reset)
ncurses-bin: /usr/bin/reset

For querying the contents of packages that are not already installed, there is the apt-file utility (not installed by default, but available from the Universe repository)

$ apt-file search -x '/reset$'
crossfire-common: /usr/share/games/crossfire/wizhelp/reset
hybserv: /usr/share/hybserv/help/chanserv/level/reset
ncurses-bin: /usr/bin/reset
ns2-examples: /usr/share/doc/ns2/examples/tcl/test/test-output-tcpReset/reset

Alternatively, you can search at http://packages.ubuntu.com/ either by package name or contents.


To actually obtain the package's source code once you have identified it, see How do I get and modify the source code of packages installed through apt-get?

steeldriver
  • 131,985
  • 21
  • 239
  • 326
  • Suggestions: 1) `apt-file` not installed by default, so you might want to mention that in the answer. 2) OP wants to read source code of the command, so you may want to include `apt-get source` command into your answer. I suggest simplifying with `apt-get source $(dpkg-query -S $(which reset) | awk -F ':' '{print $1}')` – Sergiy Kolodyazhnyy Sep 07 '15 at 18:19
  • Thanks @serg - I thought *"available from the Universe repository"* might be a strong enough hint that's it's not installed by default ;) – steeldriver Sep 07 '15 at 18:59
  • Yes, that implies it. – userDepth Sep 07 '15 at 19:32
  • And you can use the awesome debsources ... https://sources.debian.net/src/ncurses/ and browse the code (`reset` is a complex one, I think is a script generated on the fly with some Makefile magic, see https://sources.debian.net/src/ncurses/6.0%2B20150810-1/progs/Makefile.in/#L173 ) – Rmano Sep 07 '15 at 21:45