顯示具有 code 標籤的文章。 顯示所有文章
顯示具有 code 標籤的文章。 顯示所有文章

2010年1月18日 星期一

如何找 linux 指令的原始碼

上篇時, 為了了解 xargs 如何避開 argument too long 的問題, 我決定找 xargs 的原始碼來看。之前沒有這類經驗, google 一些關鍵字後毫無成果。

靈機一動, 想到初學者的好朋友 Stackoverflow。果然在那裡一搜 "linux download source code" 馬上找到解答: 在 man page 裡找出該指令屬於那個專案。像 man xargs 會發現文末這段話:
The best way to report a bug is to use the form at http://savannah.gnu.org/bugs/?group=findutils. The reason  for this is that you will then be able to track progress in fixing the problem. Other comments about xargs(1) and about the findutils package in general can be sent to the bug-findutils mailing list. To join the list, send email to bug-findutils-request@gnu.org.
於是 google findutils 就會找到它的官網, 裡面提到此專案包含 xargs, 附有下載鏈結。

在 Ubuntu 的作法

用 apt-get source PACKAGE 下載原始碼。前置作業如下:
  1. 確定 /etc/apt/sources.list 內有含 deb-src, 比方說加入這兩行:

    deb-src http://us.archive.ubuntu.com/ubuntu jaunty main restricted
    deb-src http://us.archive.ubuntu.com/ubuntu jaunty universe multiverse
  2. sudo apt-get update
可以用 aptitude show PACKAGE / COMMAND 來查 PACKAGE 名稱, 比方「 aptitude show host 」會告知 host 被包在 dnsutils 裡。或是用 apt-file search FILE 來找 PACKAGE, 像是「 apt-file search /usr/bin/xargs 」會列出 findutils。

在 Fedora 下裝 id-utils

Fedora 似乎因為執行檔撞名,而沒有提供 id-utils 的套件 ,但這是使用 gj 的必要套件,只好自己編。從官網抓好 tarball ,解開來編譯 (./configure && make)就是了。 但編譯後會遇到錯誤: ./stdio.h:10...