1. 比较文件

$ diff file1 file2

2. 比较文件夹

$ diff -urNa dir1 dir2
-u, -U NUM, --unified[=NUM] output NUM (default ) lines of unified context
-r, --recursive recursively compare any subdirectories found
--no-dereference don't follow symbolic links
-N, --new-file treat absent files as empty
--unidirectional-new-file treat absent first files as empty
--ignore-file-name-case ignore case when comparing file names
--no-ignore-file-name-case consider case when comparing file names
-a, --text treat all files as text
--strip-trailing-cr strip trailing carriage return on input

对于其中一方缺失的文件,仅输出文件名及其所在的文件夹名称:

$ diff -rua dir1 dir2

3. diff命令的参数及完整用法说明

$ diff --help
Usage: diff [OPTION]... FILES
Compare FILES line by line. Mandatory arguments to long options are mandatory for short options too.
--normal output a normal diff (the default)
-q, --brief report only when files differ
-s, --report-identical-files report when two files are the same
-c, -C NUM, --context[=NUM] output NUM (default ) lines of copied context
-u, -U NUM, --unified[=NUM] output NUM (default ) lines of unified context
-e, --ed output an ed script
-n, --rcs output an RCS format diff
-y, --side-by-side output in two columns
-W, --width=NUM output at most NUM (default ) print columns
--left-column output only the left column of common lines
--suppress-common-lines do not output common lines -p, --show-c-function show which C function each change is in
-F, --show-function-line=RE show the most recent line matching RE
--label LABEL use LABEL instead of file name
(can be repeated) -t, --expand-tabs expand tabs to spaces in output
-T, --initial-tab make tabs line up by prepending a tab
--tabsize=NUM tab stops every NUM (default ) print columns
--suppress-blank-empty suppress space or tab before empty output lines
-l, --paginate pass output through 'pr' to paginate it -r, --recursive recursively compare any subdirectories found
--no-dereference don't follow symbolic links
-N, --new-file treat absent files as empty
--unidirectional-new-file treat absent first files as empty
--ignore-file-name-case ignore case when comparing file names
--no-ignore-file-name-case consider case when comparing file names
-x, --exclude=PAT exclude files that match PAT
-X, --exclude-from=FILE exclude files that match any pattern in FILE
-S, --starting-file=FILE start with FILE when comparing directories
--from-file=FILE1 compare FILE1 to all operands;
FILE1 can be a directory
--to-file=FILE2 compare all operands to FILE2;
FILE2 can be a directory -i, --ignore-case ignore case differences in file contents
-E, --ignore-tab-expansion ignore changes due to tab expansion
-Z, --ignore-trailing-space ignore white space at line end
-b, --ignore-space-change ignore changes in the amount of white space
-w, --ignore-all-space ignore all white space
-B, --ignore-blank-lines ignore changes where lines are all blank
-I, --ignore-matching-lines=RE ignore changes where all lines match RE -a, --text treat all files as text
--strip-trailing-cr strip trailing carriage return on input -D, --ifdef=NAME output merged file with '#ifdef NAME' diffs
--GTYPE-group-format=GFMT format GTYPE input groups with GFMT
--line-format=LFMT format all input lines with LFMT
--LTYPE-line-format=LFMT format LTYPE input lines with LFMT
These format options provide fine-grained control over the output
of diff, generalizing -D/--ifdef.
LTYPE is 'old', 'new', or 'unchanged'. GTYPE is LTYPE or 'changed'.
GFMT (only) may contain:
%< lines from FILE1
%> lines from FILE2
%= lines common to FILE1 and FILE2
%[-][WIDTH][.[PREC]]{doxX}LETTER printf-style spec for LETTER
LETTERs are as follows for new group, lower case for old group:
F first line number
L last line number
N number of lines = L-F+
E F-
M L+
%(A=B?T:E) if A equals B then T else E
LFMT (only) may contain:
%L contents of line
%l contents of line, excluding any trailing newline
%[-][WIDTH][.[PREC]]{doxX}n printf-style spec for input line number
Both GFMT and LFMT may contain:
%% %
%c'C' the single character C
%c'\OOO' the character with octal code OOO
C the character C (other characters represent themselves) -d, --minimal try hard to find a smaller set of changes
--horizon-lines=NUM keep NUM lines of the common prefix and suffix
--speed-large-files assume large files and many scattered small changes --help display this help and exit
-v, --version output version information and exit FILES are 'FILE1 FILE2' or 'DIR1 DIR2' or 'DIR FILE...' or 'FILE... DIR'.
If --from-file or --to-file is given, there are no restrictions on FILE(s).
If a FILE is '-', read standard input.
Exit status is if inputs are the same, if different, if trouble. Report bugs to: bug-diffutils@gnu.org
GNU diffutils home page: <http://www.gnu.org/software/diffutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>

$ diff --help

[Linux] diff命令:逐行进行文件比较的更多相关文章

  1. 如何将Linux rm命令删除的文件放入垃圾箱

    因为rm命令删除的文件是不会放入垃圾箱的,所以无法恢复,下面小编就给大家介绍一种方法,通过替换Linux rm命令的方法,从而将rm命令删除的文件放入垃圾箱. 方法: 1. 在/home/userna ...

  2. Linux ln命令:在文件之间建立链接(硬链接和软链接)详解版1

    Linux ln命令:在文件之间建立链接(硬链接和软链接)详解版 < Linux创建文件及修改文件时间戳(touch命令)Linux复制文件和目录(cp命令) > <Linux就该这 ...

  3. Linux— file命令 用于辨识文件类型

    Linux file命令用于辨识文件类型. 通过file指令,我们得以辨识该文件的类型. 语法 file [-bcLvz][-f <名称文件>][-m <魔法数字文件>...] ...

  4. linux diff命令

    diff 命令是 linux上非常重要的工具,用于比较文件的内容,特别是比较两个版本不同的文件以找到改动的地方.diff在命令行中打印每一个行的改动.最新版本的diff还支持二进制文件.diff程序的 ...

  5. linux diff 命令

    diff 命令是 linux上非常重要的工具,用于比较文件的内容,特别是比较两个版本不同的文件以找到改动的地方.diff在命令行中打印每一个行的改动.最新版本的diff还支持二进制文件.diff程序的 ...

  6. LINUX DIFF命令详解

    刚才在和公司做离线IP对比,最后手工了,感觉还是比较麻烦的,遇到数据很大的时候不能手工进行了 本想用linux下的DIFF来进行对比,发现结果很乱.时间很紧最后还是手工了. 现在忙完要认认真真学习一下 ...

  7. Linux常用命令学习2---(文件搜索命令locate find、命令搜索命令whereis which、字符串搜索命令grep、帮助命令man)

     1.文件搜索命令:locate [文件名]    在后台数据库中按文件名搜索,搜索速度比find快,耗费资源更少    例子:locate test.txt,就会显示文件名包含 test.txt的所 ...

  8. Linux常用命令_(文件权限)

    Linux权限管理: 二.权限管理1.3种基本权限在Linux中,将使用系统资源的人员分为4类:超级用户.文件或目录的属主.属主的同组人和其他人员.超级用户拥有对Linux系统一切操作权限,对 于其他 ...

  9. linux常用命令:创建文件和文件夹

    1.首先说一下touch 创建文件的命令,touch可以用于创建二进制文件,用法非常简单.用法:touch+文件名,touch与文件名之间一定要有空格.图中先用之前分享过的命令来查看一下/目录下面有多 ...

随机推荐

  1. jekins 插件离线安装

    官网插件地址:http://updates.jenkins-ci.org/download/plugins/ 系统管理->插件管理->高级 选择一个下载好的插件,然后点击上传即可 然后就会 ...

  2. Springboot 学习笔记 之 Day 1

    SpringBoot快速入门 https://spring.io/ 1. SpringBoot简介Spring Boot来简化Spring应用开发,约定大于配置,去繁从简,just run就能创建一个 ...

  3. CKEditor5 基本使用

    1.引入 <script type="text/javascript" src="/plugin/ckeditor5/ckeditor.js">&l ...

  4. (GoRails )使用Vue.js制作拖拉list功能(v1-4) gem 'acts_as_list'(自动排列顺序)

    系列视频: use Vue.js to build the drag and drop support for the list themselves the cards that are under ...

  5. Confluence 6 更新目录

    当编辑目录时候的限制 你不能对你用户属于的目录进行编辑,禁用或者删除.这个能够预防管理员通过修改目录的时候讲自己属于的管理员权限从系统管理员组中删除. 这个限制对所有的用户目录类型适用.例如: 如果当 ...

  6. 看起来很懵的java内存加载面试题

    源代码如下,求结果 public class MemoryAnalyse { public static int k = 0; public static MemoryAnalyse t1 = new ...

  7. Dynamic Web Module 3.1 requires Java 1.7 or newer. 错误解决方案

    在写代码的时候工程出现了这样奇怪的bug很是蛋疼啊,经过查询解决方法,终于解决了这些个问题. 下面是解决问题的方法,和大家分享一下 (1)确定你的java工程配置使用了java 7 右键单击你的工程p ...

  8. C++中的赋值运算符重载函数(operator=)

    MyStr& operator =(const MyStr& str)//赋值运算符 { cout << "operator =" << e ...

  9. 规格化设计-----JSF(第三次博客作业)

    从20世纪60年代开始,就存在着许多不同的形式规格说明语言和软件开发方法.在形式规格说明领域一些最主要的发展过程列举如下: 1969-1972 C.A.R Hoare撰写了"计算机编程的公理 ...

  10. OAF SubTabLayoutBean隐藏子控件

    SubLayout隐藏子控件有两种方法 OASubTabLayoutBean layBean = (OASubTabLayoutBean) webBean.findIndexedChildRecurs ...