linux如何patch打修補程式
- 2021 年 5 月 23 日
- 筆記
- Linux作業系統操作, linux作業系統的命令
1. 創建2個文件 1.txt 和 2.txt 並在1.txt基礎上修改成為2.txt
book@100ask:~/patch$ ls 1.txt 2.txt book@100ask:~/patch$ cat 1.txt 111 222 333 book@100ask:~/patch$ cat 2.txt 111aaa 22 333 444 book@100ask:~/patch$
2.使用 diff -uprN 創建1.txt的修補程式文件(1.patch)
book@100ask:~/patch$ diff -uprN 1.txt 2.txt > 1.patch book@100ask:~/patch$ ls 1.patch 1.txt 2.txt
解析diff 命令參數
命令 : diff
-p //在每一更改處顯示c函數,方便程式設計師定位程式碼
-u //按修補程式統一格式輸出
-r //遞歸子目錄
-N //對於不存在的文件或者是空白文件和新增文件,在修補程式文件裡面包含新的文件內
分析修補程式文件(1.patch)
"---" 開頭表示原始文件
"+++" 開頭表示新文件
"@@" 開頭表示修補程式文件的範圍並以"@@"結尾,-開頭表示原始文件的行號範圍,+開頭表示新文件的行號範圍
"+" 開頭表示原始文件不存在,在新文件添加
"-" 開頭表示原始文件存在,但在新文件刪除了
其他的為原始文件和新文件都有的內容
book@100ask:~/patch$ ls 1.patch 1.txt 2.txt book@100ask:~/patch$ cat 1.patch --- 1.txt 2021-05-23 08:09:25.887150622 -0400 //原始文件 +++ 2.txt 2021-05-23 08:13:10.707561369 -0400 //新文件 @@ -1,3 +1,4 @@ -111 //刪除內容 -222 //刪除內容 +111aaa //新增內容 +22 //新增內容 333 //不變內容 +444 //新增內容 book@100as
