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
快速生成表格
无向图(Undirected Graph)
Fake2DB是emirozer 开发的一个生成测试数据的工具。目前支持 SQLite、MySQL、PostgreSQL 和 MongoDB。
“冰墩墩(英文:Bing Dwen Dwen,汉语拼音:bīng dūn dūn),是2022年北京冬季奥运会的吉祥物。将熊猫形象与富有超能量的冰晶外壳相结合,头部外壳造型取自冰雪运动头盔,装饰彩色光环,整体形象酷似航天员。那么本文就用python写一个冰墩墩。
APM(Application Performance Management)即应用性能管理系统,是对企业系统及时监控以实现对应用程序性能管理和故障管理的系统化解决方案。应用性能管理,主要指对企业的关键业务应用进行监控、优化,提高企业的应用的可靠性和治理,保证用户得到良好的服务,减低IT总拥有成本。
Electron页面跳转、浏览器打开链接和打开新窗口
在使用Git的过程中,不想每次都输入用户名和密码去拉取代码,所以就需要保存这些信息,那么既然有保存了,就必须有清除功能。
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问题
在Mac电脑中,如何对Git的用户名和密码进行修改呢?起初不懂Mac,所以整了很久,本文将记录如何对这个进行操作,以便后期使用。