热门关键字:  ubuntu  分区  Fedora  linux系统进程  函数

当前位置 :| 主页>Linux教程>Linux命令>

diff命令的使用

来源: 作者: 时间:2008-06-13 Tag: 点击:
摘要:本文详细介绍了diff命令的基本用法

作者:zieckey (zieckey@yahoo.com.cn)
All Rights Reserved!

有这样两个文件:

程序清单1 :hello.c

#include <stdio.h>

int main(void)
{
char msg[] = "Hello world!";

puts(msg);
printf("Welcome to use diff commond.\n");

return 0;
}


程序清单2:hello_diff.c

#include <stdio.h>
#include <stdlib.h>

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;
}

我们使用diff命令来查看这两个文件的不同之处,有一下几种方便的方法:
1、普通格式输出:
[root@localhost diff]# diff hello.c hello_diff.c
1a2
> #include <stdlib.h>
5c6
< char msg[] = "Hello world!";
---
> char msg[] = "Hello world,fome hello_diff.c";
8c9
< printf("Welcome to use diff commond.\n");
---
> printf("hello_diff.c says,'Here you are,using diff.'\n");
[root@localhost diff]#

上面的“1a2”表示后面的一个文件"hello_diff.c"比前面的一个文件"hello.c"多了一行
"5c6"表示第一个文件的第5行与第二个文件的第6行有区别

2、并排格式输出
[root@localhost diff]# diff hello.c hello_diff.c -y -W 130
#include <stdio.h> #include <stdio.h>
> #include <stdlib.h>

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("hello_diff.c says,'Here you are,using diff.'\

return 0; return 0;
} }
[root@localhost diff]#
这种并排格式的对比一目了然,可以快速找到不同的地方。
-W选择可以指定输出列的宽度,这里指定输出列宽为130

3、上下文输出格式
[root@localhost diff]# diff hello.c hello_diff.c -c
*** hello.c 2007-09-25 17:54:51.000000000 +0800
--- hello_diff.c 2007-09-25 17:56:00.000000000 +0800
***************
*** 1,11 ****
#include <stdio.h>

int main(void)
{
! char msg[] = "Hello world!";

puts(msg);
! printf("Welcome to use diff commond.\n");

return 0;
}


相关文章:
unix与linux中的inode
高级 Linux 命令精通指南
Linux命令集合
Linux补丁工具 diff + patch
section.1 start
tar命令详解
Linux - chattr & lsattr
ln 命令的使用
Linux关机命令学习
Linux - chown 中的 -R 参数
linux - umask
linux初级使用命令
sed 命令
cp 命令
Linux必学的60个命令(1)-安装与登陆
Linux必学的60个命令(2)-文件处理
APT-CDROM
[Unix通用命令]与用户相关的命令
[Unixt通用命令]定位命令
dircolors
declare
rmmod
passwd
linux的kill命令与信号控制
怎么样把man手册的内容保存到某个文件里面?
linux 逐级显示文件命令--tree
Linux grep命令的使用
7个极具危险性的Linux命令
tr命令使用方法
apt-move 制作本地源