linux系统中diff命令
2021/7/19 7:04:52
本文主要是介绍linux系统中diff命令,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1、测试文件
[root@centos79 test]# cat a.txt 3 5 6 s f s d g d e w f g e k [root@centos79 test]# cat b.txt 3 5 6 s f s d g d e w f g e k
2、直接使用diff
[root@centos79 test]# cat a.txt 3 5 6 s f s d g d e w f g e k [root@centos79 test]# cat b.txt 3 5 6 s f s d g d e w f g e k [root@centos79 test]# diff a.txt b.txt
3、修改b.txt测试
[root@centos79 test]# cat a.txt 3 5 6 s f s d g d e w f g e k [root@centos79 test]# cat b.txt 3 5 6 s f s d g d e xxx w f g e k [root@centos79 test]# diff a.txt b.txt ## 以b.txt文件为参照, a.txt文件的第二行改为 。。。才和b.txt一样 2c2 < s d g d e --- > s d g d e xxx
4、-i选项忽略大小写
[root@centos79 test]# cat a.txt 3 5 6 s f s d g d e w f g e k [root@centos79 test]# cat b.txt 3 5 6 s f s d g d E w f g e k [root@centos79 test]# diff a.txt b.txt 2c2 < s d g d e --- > s d g d E [root@centos79 test]# diff -i a.txt b.txt
5、-B选项忽略空行
[root@centos79 test]# cat a.txt 3 5 6 s f s d g d e w f g e k [root@centos79 test]# cat b.txt 3 5 6 s f s d g d e w f g e k [root@centos79 test]# diff a.txt b.txt 2a3,4 > > [root@centos79 test]# diff -B a.txt b.txt
6、-b选项忽略空字符
[root@centos79 test]# cat a.txt 3 5 6 s f s d g d e w f g e k [root@centos79 test]# cat b.txt 3 5 6 s f s d g d e w f g e k [root@centos79 test]# diff a.txt b.txt 2c2 < s d g d e --- > s d g d e [root@centos79 test]# diff -b a.txt b.txt
7、d表示(delete)删除
[root@centos79 test]# cat a.txt 3 5 6 s f s d g d e w f g e k [root@centos79 test]# cat b.txt 3 5 6 s f [root@centos79 test]# diff a.txt b.txt ## 表示a.txt和b.txt文件相比,a.txt删除2、3行后才和b.txt的1行相同 2,3d1 < s d g d e < w f g e k
8、a表示append(追加)
[root@centos79 test]# cat a.txt 3 5 6 s f s d g d e w f g e k [root@centos79 test]# cat b.txt 3 5 6 s f [root@centos79 test]# diff b.txt a.txt ## 表示b.txt和a.txt文件相比,在b.txt第1行的后面追加2、3行才和a.txt相同 1a2,3 > s d g d e > w f g e k
这篇关于linux系统中diff命令的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-04Linux系统上离线升级SSH服务的具体操作步骤-icode9专业技术文章分享
- 2024-06-0600-macOS和Linux安装和管理多个Python版本
- 2024-03-30[译]漫画SELinux概念
- 2024-03-29linux 移动文件
- 2024-03-28linux .so file
- 2024-03-28Linux 磁盘管理
- 2024-03-28Linux学习笔记(十三)磁盘管理(一):磁盘分区
- 2024-03-26linux 创建 文件
- 2024-03-25使用SecureCRT对Linux vim进行颜色设置
- 2024-03-202019-2020-12 20199317 《Linux内核原理与分析》 第十二周作业