Skip to main content

patch & diff

單一檔案
# 建立更新檔
diff -uN old.code new.code > patch.file

# 套用更新檔
patch < patch.file

# 回復更新前
patch -RE < patch.file
連續多個檔案
# 建立更新檔
diff -rupN olddir newdir > patch.dir

# 套用更新檔
patch -p1 < patch.dir

# 回復更新前
patch -RE -p1 < patch.dir
找出內容不一致的檔案
# 目錄一: asterisk_orig/
# 目錄二: asterisk_patched/

cd asterisk_orig; find ./ -name "*.c" -exec md5sum -b {} \; > ../asterisk_orig.md5; cd ../
cd asterisk_patched; find ./ -name "*.c" -exec md5sum -b {} \; > ../asterisk_patched.md5; cd ../

diff asterisk_orig.md5 asterisk_patched.md5 

273c273
< 894a111d1efa5901471820e203503039 *./channels/chan_sip.c
---
> 00116baac23473049b5801c9287fb4be *./channels/chan_sip.c

前提是 asterisk_orig 與 asterisk_patched 目錄架構及檔案名稱必須完全一樣,這通常用來找出 asterisk_patched 目錄內被更新過了哪些 .c 檔案。

 

diff 與 curl 的應用
diff <(curl http://somesite/file1) <(curl http://somesite/file2)