본문 바로가기

Programming/Linux Tip

patch 적용하기, diff, sdiff

원문 : https://blog.naver.com/zeta0807/220943464598


1. diff --brief

간략한 폴더비교를 할 일이 자주 있다. 아래와 같이 사용하면 된다.

diff --brief -r folder1/ folder2/
You said Linux, so you luck out (at least it should be available, not sure when it was added): diff --brief -r dir1/ dir2/ Should do what you need. If you also want to see differences for files that may not exist in either directory: diff --brief -Nr dir1/ dir2/ If I want find the differences between two directory trees, I usually just execute: diff -r dir1/ dir2/
2. patch 적용하기

대부분의 patch는 아래와 같이 적용하면 된다.

patch -p1 < xxxx.patch
3. diff를 사용해서 patch만들기
diff -Naur /usr/src/openvpn-2.3.2 /usr/src/openvpn-2.3.4 > openvpn.patch
4. 위에서 만든 patch파일 적용하기
# patch -p3 < /root/openvpn.patch

위의 3,4 예제에서는 /usr/src/folder에서 patch를 만들었기 때문에 적용할때도 -p3를 사용한다. 그러나 대부분은 p1을 사용하게끔 patch를 작성한다. 그러므로 2번과 같은 명령어를 사용하게 된다.

http://www.thegeekstuff.com/2014/12/patch-command-examples

5. sdiff

sdiff 를 사용해보니 상당히 유용하다. 좌우변에 차이를 보여준다.
==================
sdiff file1.txt file2.txt
Compares the files file1.txt and file2.txt side-by-side, displaying differences on standard output.