歡迎您光臨本站 註冊首頁

Linux中的<<道德經>>

←手機掃碼閱讀     火星人 @ 2014-03-12 , reply:0
  怎麼參加自由軟體項目?

1.訪問該自由軟體項目的官網
2.下載源代碼包
3.訂閱相關的郵件列表
4.讀源代碼,提交補丁到郵件列表

在學習的過程中,第4個步驟"提交補丁"一環節,我發現了個隱藏在Linux中的<<道德經>>章節,看圖




具體位於info文檔 diff -> Output Formats -> Sample diff Input

英文版<<道德經>>的第一章,如下:

     The Way that can be told of is not the eternal Way;
     The name that can be named is not the eternal name.
     The Nameless is the origin of Heaven and Earth;
     The Named is the mother of all things.
     Therefore let there always be non-being,
       so we may see their subtlety,
     And let there always be being,
       so we may see their outcome.
     The two are the same,
     But after they are produced,
       they have different names.

對應於中文:

      道可道,非常道。名可名,非常名。
  無名天地之始;有名萬物之母。
  故常無,欲以觀其妙;常有,欲以觀其徼。
  此兩者,同出而異名,同謂之玄。玄之又玄,眾妙之門。

好了,說完這個趣聞,了解一下"提交補丁"相關的知識,介紹兩個最常用的命令


* 將使用到的文件


$ cat lao
The Way that can be told of is not the eternal Way;
The name that can be named is not the eternal name.
The Nameless is the origin of Heaven and Earth;
The Named is the mother of all things.
Therefore let there always be non-being,
  so we may see their subtlety,
And let there always be being,
  so we may see their outcome.
The two are the same,
But after they are produced,
  they have different names.
$ cat tzu
The Nameless is the origin of Heaven and Earth;
The named is the mother of all things.

Therefore let there always be non-being,
  so we may see their subtlety,
And let there always be being,
  so we may see their outcome.
The two are the same,
But after they are produced,
  they have different names.
They both may be called deep and profound.
Deeper and more profound,
The door of all subtleties!

* diff

diff命令常用於比較文件、目錄,也可以用來製作補丁文件。
郵件列表中比較常用的一個diff命令是

$ diff -urNwB lao tzu
--- lao    2009-08-23 13:59:00.000000000 +0800
+++ tzu    2009-08-23 13:59:05.000000000 +0800
@@ -1,7 +1,6 @@
-The Way that can be told of is not the eternal Way;
-The name that can be named is not the eternal name.
 The Nameless is the origin of Heaven and Earth;
-The Named is the mother of all things.
+The named is the mother of all things.
+
 Therefore let there always be non-being,
   so we may see their subtlety,
 And let there always be being,
@@ -9,3 +8,6 @@
 The two are the same,
 But after they are produced,
   they have different names.
+They both may be called deep and profound.
+Deeper and more profound,
+The door of all subtleties!
$

說明:

1.

"-u" 表示使用統一格式,在比較結果中輸出上下文一些相同的行,有利於人工定位
"-r" 表示遞歸比較各個子目錄下的文件
"-N" 將不存在的文件當作空文件
"-w" 忽略對空格的比較
"-B" 忽略對空行的比較

2.

--- lao    2009-08-23 13:59:00.000000000 +0800
+++ tzu    2009-08-23 13:59:05.000000000 +0800

--- 表示要比較的第一個文件,對於打補丁,指原始文件
+++ 表示要比較的第二個文件,對於打補丁,指原始文件打完補丁后輸出的文件

3.

@@ -1,7 +1,6 @@

-1,7 "-"指第一個文件,"1,7"指從文件第1行數起,將比較下面的7行
+1,6 "+"指第二個文件,"1,6"指從文件第1行算起,將比較下面的6行

4.
@@ -1,7 +1,6 @@ 下面的內容,詳細說明了將第一個文件打補丁,輸出第二個文件的操作過程

每一行行前的標記

'+' 表示在此處增加一行到第一個文件
'-' 表示從第一個文件中的此處刪除一行
' ' 表示兩個文件該行的內容相同,保留

* patch



patch命令被用來打補丁,依據補丁文件來修改原始文件。

使用示例:

$ mkdir example
$ mkdir example_ok
$ mv lao example
$ mv tzu example_ok/lao
$ find
.
./example_ok
./example_ok/lao
./example
./example/lao
$ diff -urNwB example example_ok > example_ok.diff
$ cd example
$ patch -p1 <../example_ok.diff
patching file lao
$ cat lao
The Nameless is the origin of Heaven and Earth;
The named is the mother of all things.

Therefore let there always be non-being,
  so we may see their subtlety,
And let there always be being,
  so we may see their outcome.
The two are the same,
But after they are produced,
  they have different names.
They both may be called deep and profound.
Deeper and more profound,
The door of all subtleties!

運行完"patch -p1 <../example_ok.diff"命令,將example/lao打完補丁后
example/lao變成example_ok/lao的內容

patch命令中最重要的選項是"-pn",表示忽略路徑中第n個斜線之前的目錄
上面的示例中example_ok.diff文件有如下幾行:

diff -urNwB example/lao example_ok/lao
--- example/lao    2009-08-23 13:59:00.000000000 +0800
+++ example_ok/lao    2009-08-23 14:30:13.000000000 +0800

在example目錄下,運行"patch -p1 <../example_ok.diff"命令時
patch命令根據"example/lao"找原文件,"-p1"表示忽略第1個斜線之前的目錄
所以要修改的文件是example當前目錄下的"lao"

* 參考資源

1. GNU Diffutils Manual
http://www.gnu.org/software/diffutils/manual/html_node/Unified-Format.html#Unified%20Format
http://www.gnu.org/software/diffutils/manual/html_node/patch-Options.html#patch%20Options
http://www.gnu.org/software/diffutils/manual/html_node/index.html

2. <<嵌入式Linux應用開發完全手冊>> 人民郵電出版社 韋東山編著
P.73 4.2.6 其他命令: tar、diff、patch

3. 用info文檔學習“自由軟體詳細教程”
http://www.linuxeden.com/plus/view.php?aid=67260

linux 命令


[火星人 ] Linux中的<<道德經>>已經有667次圍觀

http://coctec.com/docs/linux/show-post-66162.html