Latest web development tutorials

Linux diff Command

Linux command Daquan Linux command Daquan

Linux diff command is used to compare differences between files.

diff progressive way, similarities and differences compare text files. To compare the specified directory, diff compares files in the directory the same file name, but does not compare which subdirectories.

grammar

diff [-abBcdefHilnNpPqrstTuvwy][-<行数>][-C <行数>][-D <巨集名称>][-I <字符或字符串>][-S <文件>][-W <宽度>][-x <文件或目录>][-X <文件>][--help][--left-column][--suppress-common-line][文件或目录1][文件或目录2]

Parameters:

  • - <Row> Specifies how many lines of text you want to display. This parameter must be used in conjunction with -c or -u parameter.
  • -a progressive or --text diff preset only compare text files.
  • -b --ignore-space-change or does not check different space character.
    • -B --ignore-Blank-lines or does not check blank lines.
    • -c Show all the text, and marked differences.
    • -C <Line number> or --context <rows> and execute "-c- <rows>" the same instruction.
    • -d or --minimal use different algorithms to smaller units for comparison.
    • -D <Macro name> or ifdef <macro name> output format of this parameter can be used to preprocessor macros.
    • -e or --ed this parameter can be used to format the output ed the script file.
    • -f Format or -forward-ed ed output similar to the script file, but the order of the original document to display a different place.
    • When -H --speed-large-files or large files, it can speed up.
    • -l <character or string> or --ignore-matching-lines <character or string> If two files differ in a few lines, but these lines at the same time contains the options specified character or string , no differences between the two files are displayed.
    • -i or --ignore-case does not check different capitalization.
    • -l or --paginate results by the pr program tab.
    • -n or --rcs will compare results in RCS format display.
    • -N Or --new-file When comparing directories, if the file A appears only in a directory, the default will be displayed:
    • Only in directory: File A If you use the -N parameter, will the diff file A comparison with a blank document.
    • -p If the compared files as C language program code file, show differences in the function name is located.
    • -P Or --unidirectional-new-file similar -N, but only if the second directory contains a directory does not have the first file, the file will be compared with the blank document.
    • -q or --brief show only whether the differences do not show detailed information.
    • -r or --recursive compare files in subdirectories.
    • -s or --report-identical-files if found no difference, still display information.
    • -S <File> or --starting-file <file> When comparing directories, start comparing from the specified file.
    • -t or --expand-tabs at the output, expand the tab character.
    • -T Or --initial-tab on the front of each line tab characters to align.
    • -u, -U <number of columns> or --unified = <number of columns> to merge different way to display the file's contents.
    • -v or --version display version information.
    • -w or --ignore-all-space Ignore all white space characters.
    • -W <Width> or --width <width> When using the -y parameter specifies the column width.
    • -x <filename or directory> or --exclude <filename or directory> does not compare the options specified file or directory.
    • -X <File> or --exclude-from <file> You can save the file or directory type into a text file, and then specify the text file in = <file> in.
    • -y or --side-by-side in a parallel way to show the similarities and differences of the file at.
    • --help displays help.
    • --left-column when using the -y parameter, if the same two lines of a file, only the content of the line in the field on the left.
    • --suppress-common-lines when using the -y parameter displays only differences.

    Example 1: compare two files

    [root@localhost test3]# diff log2014.log log2013.log 
    3c3
    < 2014-03
    ---
    > 2013-03
    8c8
    < 2013-07
    ---
    > 2013-08
    11,12d10
    < 2013-11
    < 2013-12
    

    The above "3c3" and "8c8" represents log2014.log and log20143log files differ in lines 3 and 8 lines; "11,12d10" denotes a document more than 12 rows 11 and the second file .

    Example 2: side by side output format

    [root@localhost test3]# diff log2014.log log2013.log  -y -W 50
    2013-01                 2013-01
    2013-02                 2013-02
    2014-03               | 2013-03
    2013-04                 2013-04
    2013-05                 2013-05
    2013-06                 2013-06
    2013-07                 2013-07
    2013-07               | 2013-08
    2013-09                 2013-09
    2013-10                 2013-10
    2013-11               <
    2013-12               <
    [root@localhost test3]# diff log2013.log log2014.log  -y -W 50
    2013-01                 2013-01
    2013-02                 2013-02
    2013-03               | 2014-03
    2013-04                 2013-04
    2013-05                 2013-05
    2013-06                 2013-06
    2013-07                 2013-07
    2013-08               | 2013-07
    2013-09                 2013-09
    2013-10                 2013-10
                          > 2013-11
                          > 2013-12
    

    Explanation:

    • "|" Represents the contents of the file before and after the two different
    • "<" Indicates that the following files before the file less than 1 lines
    • ">" Stands for the file before the file more than 1 lines

    Linux command Daquan Linux command Daquan