diff 명령
diff 명령은 파일 두개를 비교해서 차이를 보여주는 기능을 한다.
일반적으로 diff 명령을 실행하면 다음과 같이 문맥형식(<,>사용)하여 두파일의 차이를 보여준다.
[citylock@localhost linuxTest]$ diff 1.c 2.c
4c4
< void main()
---
> int main(int argc, char **argv)
6,7c6,8
< /* follow printf line has syntax error */
< printf(hello,world);
---
> /* fixed syntax error */
> printf("hello,world");
> return 0;
위의 코드보다는 -u 옵션을 추가하여 통합형식(-,+)를 이용하는 것이 두파일을 비교하는데 좀더 효과적인다.
[citylock@localhost linuxTest]$ diff -u 1.c 2.c
--- 1.c 2008-05-14 16:21:15.000000000 +0900
+++ 2.c 2008-05-14 16:22:37.000000000 +0900
@@ -1,9 +1,10 @@
/* this program demonstrates diff(1) utility */
#include <stdio.h>
-void main()
+int main(int argc, char **argv)
{
- /* follow printf line has syntax error */
- printf(hello,world);
+ /* fixed syntax error */
+ printf("hello,world");
+ return 0;
}
따라서, 두개의 파일 비교할때는 diff -u file1 file2 를 이용하자.
tip ================================================
.bashrc 에 alias로 diff -u 로 지정해 놓으면 편리하다.
$ aliase diff='diff -u'
2개의 파일/디렉토리를 비교해 주는 유틸리티
윈도우즈용 - windiff.exe
리눅스용 - xxdif, KDiff3
맥OS - filemerge