diff:比较两个文件的不同
简介diff命令可以逐行比较纯文本文件的内容,并输出文件的差异
说明
diff命令可以逐行比较纯文本文件的内容,并输出文件的差异
格式
diff [option] [file1] [file2]
常用参数说明
- -y:以并列的方式显示文件的异同之处
- -c:使用上下文的输出方式
- -W:在使用-y参数时,指定显示宽度
- -u:使用统一的格式输出
示例
1、默认情况下
[root@localhost ~]# cat diff1.txt
i
am
is
xiaohai
today
[root@localhost ~]# cat diff2.txt
hello
world
is
xiaohai
very
good
[root@localhost ~]# diff diff1.txt diff2.txt
1,2c1,2 #第一个文件的1到2行改变成第二个文件的1,2行
< i
< am
---
> hello
> world
5c5,6 #第一个文件的第五号改成第二个文件的5到6行
< today
---
> very
> good
diff默认情况下有三种提示:
a:增加
c:改变
d:删除
5c5,6或者1,2c1,2:字母前面是文件1的行号,字母后面是文件2的行号。其中<开头的是文件1,>开头的属于文件2
2、并排显示差异
[root@localhost ~]# diff -y diff1.txt diff2.txt
i | hello
am | world
is is
xiaohai xiaohai
today | very
> good
#如果上面对比宽度较大,那么可以是-W来控制
[root@localhost ~]# diff -y -W 30 diff1.txt diff2.txt
i | hello
am | world
is is
xiaohai xiaohai
today | very
> good
3、上下文输出
[root@localhost ~]# diff -c diff1.txt diff2.txt
*** diff1.txt 2018-06-04 11:56:25.159021083 -0400
--- diff2.txt 2018-06-04 11:55:56.554022518 -0400
***************
*** 1,5 ****
! i
! am
is
xiaohai
! today
--- 1,6 ----
! hello
! world
is
xiaohai
! very
! good
命令结果说明如下:
-:表示文件2比文件1少的行数
+:表示文件2比文件1多的行数
!:表示文件2与文件1不同行数
4、统一格式输出
[root@localhost ~]# diff -u diff1.txt diff2.txt
--- diff1.txt 2018-06-04 11:56:25.159021083 -0400
+++ diff2.txt 2018-06-04 11:55:56.554022518 -0400
@@ -1,5 +1,6 @@
-i
-am
+hello
+world
is
xiaohai
-today
+very
+good
5、还可以比较目录
[root@localhost ~]# diff /etc/rc3.d/ /etc/rc6.d/
Only in /etc/rc6.d/: K36mysqld
Only in /etc/rc6.d/: K79iprdump
Only in /etc/rc6.d/: K80iprinit
Only in /etc/rc6.d/: K80iprupdate
Only in /etc/rc6.d/: K90network
Only in /etc/rc3.d/: S10network
Only in /etc/rc3.d/: S20iprinit
Only in /etc/rc3.d/: S20iprupdate
Only in /etc/rc3.d/: S21iprdump
Only in /etc/rc3.d/: S64mysqld
6、修改下diff2.txt文件,删除前两行,然后执行上面的命令
[root@localhost ~]# diff -y diff1.txt diff2.txt
i <
am <
is is
xiaohai xiaohai
today | very
> good
[root@localhost ~]# diff -c diff1.txt diff2.txt
*** diff1.txt 2018-06-04 11:56:25.159021083 -0400
--- diff2.txt 2018-06-04 12:07:10.105988728 -0400
***************
*** 1,5 ****
- i
- am
is
xiaohai
! today
--- 1,4 ----
is
xiaohai
! very
! good
[root@localhost ~]# diff -u diff1.txt diff2.txt
--- diff1.txt 2018-06-04 11:56:25.159021083 -0400
+++ diff2.txt 2018-06-04 12:07:10.105988728 -0400
@@ -1,5 +1,4 @@
-i
-am
is
xiaohai
-today
+very
+good
很多时候我们只希望我们的应用只能启动一次,本文主要介绍下Flutter的windows桌面端如何实现只启动一次的方法。
无向图(Undirected Graph)
《是妈妈是女儿》聚焦母女间未曾言明的爱意,以书信对话的形式呈现出各自的内心独白,表达彼此的牵挂。黄绮珊与希林娜依·高用跨越时空、打开心扉、深情对唱的形式,将天下母女爱的寄语化作心灵的倾诉。黄绮珊的每一句话,每一个字都演绎出了妈妈对女儿的爱,而希林依娜·高把女儿对妈妈的爱由不理解到理解再到感恩演绎得淋漓尽致。
Python调用WPS把文档转换PDF,并把PDF转图片,首先需要安装WPS,然后利用pypiwin32把文档转化成PDF,再利用fitz、PyMuPD把PDF转化成图片
GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务。
快速生成表格
Electron页面跳转、浏览器打开链接和打开新窗口
Docker编译镜像出现:fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.12/main: temporary error (try again later)
WARNING: Ignoring APKINDEX.2c4ac24e.tar.gz: No such file or directory问题
在使用Git的过程中,不想每次都输入用户名和密码去拉取代码,所以就需要保存这些信息,那么既然有保存了,就必须有清除功能。
在Mac电脑中,如何对Git的用户名和密码进行修改呢?起初不懂Mac,所以整了很久,本文将记录如何对这个进行操作,以便后期使用。