{
    "mode": "man",
    "parameter": "diff",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/man/diff/json",
    "generated": "2026-07-06T02:03:34Z",
    "synopsis": "diff [OPTION]... FILES",
    "sections": {
        "NAME": {
            "content": "diff - compare files line by line\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "diff [OPTION]... FILES\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Compare FILES line by line.\n\nMandatory arguments to long options are mandatory for short options too.\n",
            "subsections": [
                {
                    "name": "--normal",
                    "content": "output a normal diff (the default)\n",
                    "long": "--normal"
                },
                {
                    "name": "-q --brief",
                    "content": "report only when files differ\n",
                    "flag": "-q",
                    "long": "--brief"
                },
                {
                    "name": "-s --report-identical-files",
                    "content": "report when two files are the same\n",
                    "flag": "-s",
                    "long": "--report-identical-files"
                },
                {
                    "name": "-c -C --context",
                    "content": "output NUM (default 3) lines of copied context\n",
                    "flag": "-C",
                    "long": "--context"
                },
                {
                    "name": "-u -U --unified",
                    "content": "output NUM (default 3) lines of unified context\n",
                    "flag": "-U",
                    "long": "--unified"
                },
                {
                    "name": "-e --ed",
                    "content": "output an ed script\n",
                    "flag": "-e",
                    "long": "--ed"
                },
                {
                    "name": "-n --rcs",
                    "content": "output an RCS format diff\n",
                    "flag": "-n",
                    "long": "--rcs"
                },
                {
                    "name": "-y --side-by-side",
                    "content": "output in two columns\n",
                    "flag": "-y",
                    "long": "--side-by-side"
                },
                {
                    "name": "-W --width",
                    "content": "output at most NUM (default 130) print columns\n",
                    "flag": "-W",
                    "long": "--width"
                },
                {
                    "name": "--left-column",
                    "content": "output only the left column of common lines\n",
                    "long": "--left-column"
                },
                {
                    "name": "--suppress-common-lines",
                    "content": "do not output common lines\n",
                    "long": "--suppress-common-lines"
                },
                {
                    "name": "-p --show-c-function",
                    "content": "show which C function each change is in\n",
                    "flag": "-p",
                    "long": "--show-c-function"
                },
                {
                    "name": "-F --show-function-line",
                    "content": "show the most recent line matching RE\n\n--label LABEL\nuse LABEL instead of file name and timestamp (can be repeated)\n",
                    "flag": "-F",
                    "long": "--show-function-line"
                },
                {
                    "name": "-t --expand-tabs",
                    "content": "expand tabs to spaces in output\n",
                    "flag": "-t",
                    "long": "--expand-tabs"
                },
                {
                    "name": "-T --initial-tab",
                    "content": "make tabs line up by prepending a tab\n\n--tabsize=NUM\ntab stops every NUM (default 8) print columns\n",
                    "flag": "-T",
                    "long": "--initial-tab"
                },
                {
                    "name": "--suppress-blank-empty",
                    "content": "suppress space or tab before empty output lines\n",
                    "long": "--suppress-blank-empty"
                },
                {
                    "name": "-l --paginate",
                    "content": "pass output through 'pr' to paginate it\n",
                    "flag": "-l",
                    "long": "--paginate"
                },
                {
                    "name": "-r --recursive",
                    "content": "recursively compare any subdirectories found\n",
                    "flag": "-r",
                    "long": "--recursive"
                },
                {
                    "name": "--no-dereference",
                    "content": "don't follow symbolic links\n",
                    "long": "--no-dereference"
                },
                {
                    "name": "-N --new-file",
                    "content": "treat absent files as empty\n",
                    "flag": "-N",
                    "long": "--new-file"
                },
                {
                    "name": "--unidirectional-new-file",
                    "content": "treat absent first files as empty\n",
                    "long": "--unidirectional-new-file"
                },
                {
                    "name": "--ignore-file-name-case",
                    "content": "ignore case when comparing file names\n",
                    "long": "--ignore-file-name-case"
                },
                {
                    "name": "--no-ignore-file-name-case",
                    "content": "consider case when comparing file names\n",
                    "long": "--no-ignore-file-name-case"
                },
                {
                    "name": "-x --exclude",
                    "content": "exclude files that match PAT\n",
                    "flag": "-x",
                    "long": "--exclude"
                },
                {
                    "name": "-X --exclude-from",
                    "content": "exclude files that match any pattern in FILE\n",
                    "flag": "-X",
                    "long": "--exclude-from"
                },
                {
                    "name": "-S --starting-file",
                    "content": "start with FILE when comparing directories\n\n--from-file=FILE1\ncompare FILE1 to all operands; FILE1 can be a directory\n\n--to-file=FILE2\ncompare all operands to FILE2; FILE2 can be a directory\n",
                    "flag": "-S",
                    "long": "--starting-file"
                },
                {
                    "name": "-i --ignore-case",
                    "content": "ignore case differences in file contents\n",
                    "flag": "-i",
                    "long": "--ignore-case"
                },
                {
                    "name": "-E --ignore-tab-expansion",
                    "content": "ignore changes due to tab expansion\n",
                    "flag": "-E",
                    "long": "--ignore-tab-expansion"
                },
                {
                    "name": "-Z --ignore-trailing-space",
                    "content": "ignore white space at line end\n",
                    "flag": "-Z",
                    "long": "--ignore-trailing-space"
                },
                {
                    "name": "-b --ignore-space-change",
                    "content": "ignore changes in the amount of white space\n",
                    "flag": "-b",
                    "long": "--ignore-space-change"
                },
                {
                    "name": "-w --ignore-all-space",
                    "content": "ignore all white space\n",
                    "flag": "-w",
                    "long": "--ignore-all-space"
                },
                {
                    "name": "-B --ignore-blank-lines",
                    "content": "ignore changes where lines are all blank\n",
                    "flag": "-B",
                    "long": "--ignore-blank-lines"
                },
                {
                    "name": "-I --ignore-matching-lines",
                    "content": "ignore changes where all lines match RE\n",
                    "flag": "-I",
                    "long": "--ignore-matching-lines"
                },
                {
                    "name": "-a --text",
                    "content": "treat all files as text\n",
                    "flag": "-a",
                    "long": "--text"
                },
                {
                    "name": "--strip-trailing-cr",
                    "content": "strip trailing carriage return on input\n",
                    "long": "--strip-trailing-cr"
                },
                {
                    "name": "-D --ifdef",
                    "content": "output merged file with '#ifdef NAME' diffs\n\n--GTYPE-group-format=GFMT\nformat GTYPE input groups with GFMT\n\n--line-format=LFMT\nformat all input lines with LFMT\n\n--LTYPE-line-format=LFMT\nformat LTYPE input lines with LFMT\n\nThese format options provide fine-grained control over the output\n\nof diff, generalizing -D/--ifdef.\n\nLTYPE is 'old', 'new', or 'unchanged'.\nGTYPE is LTYPE or 'changed'.\n\nGFMT (only) may contain:\n\n%<     lines from FILE1\n\n%>     lines from FILE2\n\n%=     lines common to FILE1 and FILE2\n\n%[-][WIDTH][.[PREC]]{doxX}LETTER\nprintf-style spec for LETTER\n\nLETTERs are as follows for new group, lower case for old group:\n\nF      first line number\n\nL      last line number\n\nN      number of lines = L-F+1\n\nE      F-1\n\nM      L+1\n\n%(A=B?T:E)\nif A equals B then T else E\n\nLFMT (only) may contain:\n\n%L     contents of line\n\n%l     contents of line, excluding any trailing newline\n\n%[-][WIDTH][.[PREC]]{doxX}n\nprintf-style spec for input line number\n\nBoth GFMT and LFMT may contain:\n\n%%     %\n\n%c'C'  the single character C\n\n%c'\\OOO'\nthe character with octal code OOO\n\nC      the character C (other characters represent themselves)\n",
                    "flag": "-D",
                    "long": "--ifdef"
                },
                {
                    "name": "-d --minimal",
                    "content": "try hard to find a smaller set of changes\n\n--horizon-lines=NUM\nkeep NUM lines of the common prefix and suffix\n",
                    "flag": "-d",
                    "long": "--minimal"
                },
                {
                    "name": "--speed-large-files",
                    "content": "assume large files and many scattered small changes\n\n--color[=WHEN]\ncolor output; WHEN is 'never', 'always', or 'auto'; plain --color means --color='auto'\n\n--palette=PALETTE\nthe  colors  to  use when --color is active; PALETTE is a colon-separated list of ter‐\nminfo capabilities\n\n--help display this help and exit\n",
                    "long": "--speed-large-files"
                },
                {
                    "name": "-v --version",
                    "content": "output version information and exit\n\nFILES are 'FILE1 FILE2' or 'DIR1 DIR2' or 'DIR  FILE'  or  'FILE  DIR'.   If  --from-file  or\n--to-file  is  given,  there are no restrictions on FILE(s).  If a FILE is '-', read standard\ninput.  Exit status is 0 if inputs are the same, 1 if different, 2 if trouble.\n",
                    "flag": "-v",
                    "long": "--version"
                }
            ]
        },
        "AUTHOR": {
            "content": "Written by Paul Eggert, Mike Haertel, David Hayes, Richard Stallman, and Len Tower.\n",
            "subsections": []
        },
        "REPORTING BUGS": {
            "content": "Report bugs to: bug-diffutils@gnu.org\nGNU diffutils home page: <https://www.gnu.org/software/diffutils/>\nGeneral help using GNU software: <https://www.gnu.org/gethelp/>\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright © 2021 Free Software Foundation, Inc.  License GPLv3+: GNU GPL version 3  or  later\n<https://gnu.org/licenses/gpl.html>.\nThis  is free software: you are free to change and redistribute it.  There is NO WARRANTY, to\nthe extent permitted by law.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "wdiff(1), cmp(1), diff3(1), sdiff(1), patch(1)\n\nThe full documentation for diff is maintained as a Texinfo manual.  If the info and diff pro‐\ngrams are properly installed at your site, the command\n\ninfo diff\n\nshould give you access to the complete manual.\n\n\n\ndiffutils 3.8                                August 2021                                     DIFF(1)",
            "subsections": []
        }
    },
    "summary": "diff - compare files line by line",
    "flags": [
        {
            "flag": "",
            "long": "--normal",
            "arg": null,
            "description": "output a normal diff (the default)"
        },
        {
            "flag": "-q",
            "long": "--brief",
            "arg": null,
            "description": "report only when files differ"
        },
        {
            "flag": "-s",
            "long": "--report-identical-files",
            "arg": null,
            "description": "report when two files are the same"
        },
        {
            "flag": "-C",
            "long": "--context",
            "arg": null,
            "description": "output NUM (default 3) lines of copied context"
        },
        {
            "flag": "-U",
            "long": "--unified",
            "arg": null,
            "description": "output NUM (default 3) lines of unified context"
        },
        {
            "flag": "-e",
            "long": "--ed",
            "arg": null,
            "description": "output an ed script"
        },
        {
            "flag": "-n",
            "long": "--rcs",
            "arg": null,
            "description": "output an RCS format diff"
        },
        {
            "flag": "-y",
            "long": "--side-by-side",
            "arg": null,
            "description": "output in two columns"
        },
        {
            "flag": "-W",
            "long": "--width",
            "arg": null,
            "description": "output at most NUM (default 130) print columns"
        },
        {
            "flag": "",
            "long": "--left-column",
            "arg": null,
            "description": "output only the left column of common lines"
        },
        {
            "flag": "",
            "long": "--suppress-common-lines",
            "arg": null,
            "description": "do not output common lines"
        },
        {
            "flag": "-p",
            "long": "--show-c-function",
            "arg": null,
            "description": "show which C function each change is in"
        },
        {
            "flag": "-F",
            "long": "--show-function-line",
            "arg": null,
            "description": "show the most recent line matching RE --label LABEL use LABEL instead of file name and timestamp (can be repeated)"
        },
        {
            "flag": "-t",
            "long": "--expand-tabs",
            "arg": null,
            "description": "expand tabs to spaces in output"
        },
        {
            "flag": "-T",
            "long": "--initial-tab",
            "arg": null,
            "description": "make tabs line up by prepending a tab --tabsize=NUM tab stops every NUM (default 8) print columns"
        },
        {
            "flag": "",
            "long": "--suppress-blank-empty",
            "arg": null,
            "description": "suppress space or tab before empty output lines"
        },
        {
            "flag": "-l",
            "long": "--paginate",
            "arg": null,
            "description": "pass output through 'pr' to paginate it"
        },
        {
            "flag": "-r",
            "long": "--recursive",
            "arg": null,
            "description": "recursively compare any subdirectories found"
        },
        {
            "flag": "",
            "long": "--no-dereference",
            "arg": null,
            "description": "don't follow symbolic links"
        },
        {
            "flag": "-N",
            "long": "--new-file",
            "arg": null,
            "description": "treat absent files as empty"
        },
        {
            "flag": "",
            "long": "--unidirectional-new-file",
            "arg": null,
            "description": "treat absent first files as empty"
        },
        {
            "flag": "",
            "long": "--ignore-file-name-case",
            "arg": null,
            "description": "ignore case when comparing file names"
        },
        {
            "flag": "",
            "long": "--no-ignore-file-name-case",
            "arg": null,
            "description": "consider case when comparing file names"
        },
        {
            "flag": "-x",
            "long": "--exclude",
            "arg": null,
            "description": "exclude files that match PAT"
        },
        {
            "flag": "-X",
            "long": "--exclude-from",
            "arg": null,
            "description": "exclude files that match any pattern in FILE"
        },
        {
            "flag": "-S",
            "long": "--starting-file",
            "arg": null,
            "description": "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"
        },
        {
            "flag": "-i",
            "long": "--ignore-case",
            "arg": null,
            "description": "ignore case differences in file contents"
        },
        {
            "flag": "-E",
            "long": "--ignore-tab-expansion",
            "arg": null,
            "description": "ignore changes due to tab expansion"
        },
        {
            "flag": "-Z",
            "long": "--ignore-trailing-space",
            "arg": null,
            "description": "ignore white space at line end"
        },
        {
            "flag": "-b",
            "long": "--ignore-space-change",
            "arg": null,
            "description": "ignore changes in the amount of white space"
        },
        {
            "flag": "-w",
            "long": "--ignore-all-space",
            "arg": null,
            "description": "ignore all white space"
        },
        {
            "flag": "-B",
            "long": "--ignore-blank-lines",
            "arg": null,
            "description": "ignore changes where lines are all blank"
        },
        {
            "flag": "-I",
            "long": "--ignore-matching-lines",
            "arg": null,
            "description": "ignore changes where all lines match RE"
        },
        {
            "flag": "-a",
            "long": "--text",
            "arg": null,
            "description": "treat all files as text"
        },
        {
            "flag": "",
            "long": "--strip-trailing-cr",
            "arg": null,
            "description": "strip trailing carriage return on input"
        },
        {
            "flag": "-D",
            "long": "--ifdef",
            "arg": null,
            "description": "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+1 E F-1 M L+1 %(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)"
        },
        {
            "flag": "-d",
            "long": "--minimal",
            "arg": null,
            "description": "try hard to find a smaller set of changes --horizon-lines=NUM keep NUM lines of the common prefix and suffix"
        },
        {
            "flag": "",
            "long": "--speed-large-files",
            "arg": null,
            "description": "assume large files and many scattered small changes --color[=WHEN] color output; WHEN is 'never', 'always', or 'auto'; plain --color means --color='auto' --palette=PALETTE the colors to use when --color is active; PALETTE is a colon-separated list of ter‐ minfo capabilities --help display this help and exit"
        },
        {
            "flag": "-v",
            "long": "--version",
            "arg": null,
            "description": "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 0 if inputs are the same, 1 if different, 2 if trouble."
        }
    ],
    "examples": [],
    "see_also": [
        {
            "name": "wdiff",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/wdiff/1/json"
        },
        {
            "name": "cmp",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/cmp/1/json"
        },
        {
            "name": "diff3",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/diff3/1/json"
        },
        {
            "name": "sdiff",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/sdiff/1/json"
        },
        {
            "name": "patch",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/patch/1/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Compare files and directories.",
        "examples": [
            {
                "description": "Compare files (lists changes to turn `old_file` into `new_file`)",
                "command": "diff {{path/to/old_file}} {{path/to/new_file}}"
            },
            {
                "description": "Compare files, ignoring white spaces",
                "command": "diff {{-w|--ignore-all-space}} {{path/to/old_file}} {{path/to/new_file}}"
            },
            {
                "description": "Compare files, showing the differences side by side",
                "command": "diff {{-y|--side-by-side}} {{path/to/old_file}} {{path/to/new_file}}"
            },
            {
                "description": "Compare files, showing the differences in unified format (as used by `git diff`)",
                "command": "diff {{-u|--unified}} {{path/to/old_file}} {{path/to/new_file}}"
            },
            {
                "description": "Compare directories recursively (shows names for differing files/directories as well as changes made to files)",
                "command": "diff {{-r|--recursive}} {{path/to/old_directory}} {{path/to/new_directory}}"
            },
            {
                "description": "Compare directories, only showing the names of files that differ",
                "command": "diff {{-r|--recursive}} {{-q|--brief}} {{path/to/old_directory}} {{path/to/new_directory}}"
            },
            {
                "description": "Create a patch file for Git from the differences of two text files, treating nonexistent files as empty",
                "command": "diff {{-a|--text}} {{-u|--unified}} {{-N|--new-file}} {{path/to/old_file}} {{path/to/new_file}} > {{path/to/diff.patch}}"
            },
            {
                "description": "Compare files, showing output in color, trying hard to find the smallest set of changes",
                "command": "diff {{-d|--minimal}} --color=always {{path/to/old_file}} {{path/to/new_file}}"
            }
        ]
    }
}