新建两个示例文件如下:
hello.c
#include int main(void) { char msg[] = "Hello world!"; puts(msg); printf("Welcome to use diff commond.\n"); return 0; }
|
hello_diff.c
#include #include int main(void) { char msg[] = "Hello world,fome hello_diff.c"; puts(msg); printf("hello_diff.c says,'Here you are,using diff.'\n"); return 0; }
|
1:普通输出
diff hello.c hello_diff.c
1a2 > #include 4c5 < char msg[] = "Hello world!"; --- > char msg[] = "Hello world,fome hello_diff.c"; 7c8 < printf("Welcome to use diff commond.\n"); --- > printf("hello_diff.c says,'Here you are,using diff.'\n");
|
"1a2”表示后面的一个文件"hello_diff.c"比前面的一个文件"hello.c"多了一行,"4c5"表示第一个文件的第4行与第二个文件的第5行有区别
2:并排输出
diff hello.c hello_diff.c -y -W 130
#include #include > #include int main(void) int main(void) { { char msg[] = "Hello world!"; | char msg[] = "Hello world,fome hello_diff.c";
puts(msg); puts(msg); printf("Welcome to use diff commond.\n"); | printf("Welcome to use diff commond.\n");
|
"-W 130”表示列宽设为130
3:上下文输出
diff hello.c hello_diff.c -c
*** hello.c 2010-11-12 09:59:41.000000000 +0800 --- hello_diff.c 2010-11-12 10:00:13.000000000 +0800 *************** *** 1,10 **** #include int main(void) { ! char msg[] = "Hello world!"; puts(msg); ! printf("Welcome to use diff commond.\n"); return 0; } --- 1,11 ---- #include + #include int main(void) { ! char msg[] = "Hello world,fome hello_diff.c"; puts(msg); ! printf("hello_diff.c says,'Here you are,using diff.'\n"); return 0; }
|
4:统一输出
diff hello.c hello_diff.c -u
--- hello.c 2010-11-12 09:59:41.000000000 +0800 +++ hello_diff.c 2010-11-12 10:00:13.000000000 +0800 @@ -1,10 +1,11 @@ #include +#include int main(void) { - char msg[] = "Hello world!"; + char msg[] = "Hello world,fome hello_diff.c"; puts(msg); - printf("Welcome to use diff commond.\n"); + printf("hello_diff.c says,'Here you are,using diff.'\n"); return 0; }
|
阅读(722) | 评论(0) | 转发(0) |