One linux command every day (36): diff command link: One linux command every day (1): ls command http://www.2cto.com/os/201210/163049.html ; One linux command every day (2): cd command http://www.2cto.com/os/201210/163050.html A linux command (36): diff command every day link: A linux command every day (1): ls command http://www.2cto.com/os/201210/163049.html ; One linux command every day (2): cd command http://www.2cto.com/os/201210/163050.html ; One linux command every day (3): pwd command http://www.2cto.com/os/201210/163462.html ; One linux command every day (4): mkdir command http://www.2cto.com/os/201210/163463.html ; One linux command every day (5): rm command http://www.2cto.com/os/201210/163662.html ; One linux command (6) every day: rmdir command http://www.2cto.com/os/201210/164017.html ; One linux command (7) every day: mv command http://www.2cto.com/os/201210/164247.html ; One linux command every day (8): cp command http://www.2cto.com/os/201210/164254.html ; One linux command every day (9): touch Command http://www.2cto.com/os/201211/165699.html ; One linux command every day (10): cat command http://www.2cto.com/os/201211/165989.html ; One linux command every day (11): nl command http://www.2cto.com/os/201211/165990.html One linux command every day (12): more command http://www.2cto.com/os/201211/165994.html One linux command every day (13): less command http://www.2cto.com/os/201211/165998.html One linux command every day (14): head Command http://www.2cto.com/os/201211/166191.html One linux command every day (15): tail command http://www.2cto.com/os/201211/168702.html One linux command every day (16): which command http://www.2cto.com/os/201211/168890.html A linux command (17) every day: whereis command http://www.2cto.com/os/201211/168893.html One linux command (18) every day: locate command http://www.2cto.com/os/201211/168895.html One linux command every day (19): find command overview http://www.2cto.com/os/201211/168897.html One linux command every day (20): find command exec http://www.2cto.com/os/201211/168901.html One linux command (21) every day: find command xargs http://www.2cto.com/os/201211/168903.html A linux command (22) every day: detailed description of the parameters of the find Command http://www.2cto.com/os/201211/168912.html A linux command (23) every day: Linux directory structure http://www.2cto.com/os/201211/170430.html One linux command every day (24): Linux file type and extension http://www.2cto.com/os/201211/170431.html One linux command every day (25): Explanation of linux file attributes http://www.2cto.com/os/201211/170434.html One linux command every day (26): use SecureCRT to upload and download files http://www.2cto.com/os/201211/172022.html One linux command every day (27): linux chmod command http://www.2cto.com/os/201211/172028.html One linux command every day (28): tar command http://www.2cto.com/os/201212/172641.html One linux command (29) every day: chgrp command http://www.2cto.com/os/201212/172983.html One linux command every day (30): chown command http://www.2cto.com/os/201212/173239.html A linux command (31) every day:/etc/group file details http://www.2cto.com/os/201212/174429.html One linux command (32) every day: gzip command http://www.2cto.com/os/201212/174431.html One linux command every day (33): df command http://www.2cto.com/os/201212/174434.html One linux command every day (34): du command http://www.2cto.com/os/201212/174701.html One linux command (35) every day: ln command http://www.2cto.com/os/201212/174993.html The diff command is an important tool in linux. it is used to compare the content of files, especially files of different versions, to find the changes. Diff prints the changes of each line in the command line. The latest diff version also supports binary files. The output of the diff program is called a patch. because there is a patch program in the Linux system, the content of the. c file can be updated to B. c according to the diff output. Diff is an indispensable part of version control tools such as svn, cvs, and git. Www.2cto.com 1. command format: diff [parameter] [file 1 or directory 1] [File 2 or directory 2] 2. command function: the diff command can compare the content of a single file or directory. If you specify a file to be compared, it is valid only when the input is a text file. Compare the similarities and differences of text files in line-by-line mode. If a directory is compared, the diff command compares two text files with the same name. List different binary files, public subdirectories, and files that only appear in one directory. 3. command parameter:-specifies the number of lines of text to be displayed. This parameter must be used with the-c or-u parameter. -A or -- text diff: by default, only text files are compared row by row. -B or -- ignore-space-change do not check the difference of space characters. -B or -- ignore-blank-lines do not check blank lines. -C: display all internal text and mark the differences. -C or -- context is the same as executing the "-c-" command. -D or -- minimal uses different algorithms for comparison in smaller units. -D or ifdef the output format of this parameter can be used for the Frontend Processor. -E or -- ed the output format of this parameter can be used in the script file of ed. The format output by-f or-forward-ed is similar to that output by ed script files, but different places are displayed in the order of the original files. -H or -- speed-large-files can accelerate the speed of large files. -L or -- ignore-matching-lines. if the two files are in different lines, these lines both contain the character or string specified in the option, the differences between the two files are not displayed. -I or -- ignore-case do not check the case sensitivity. Www.2cto.com-l or -- paginate submit the results to the pr program for paging. -N or -- rcs: The comparison result is displayed in the format of RCS. -N or -- new-file when comparing directories, if file A Only appears in A directory, the default is: Only in Directory: If file A uses the-N parameter, then, diff compares file A with A blank file. -P: if the comparison file is a C program code file, the function name of the difference is displayed. -P or -- unidirectional-new-file is similar to-N, but only when the second directory contains files not in the first Directory, to compare this file with a blank file. -Q or -- brief only shows no difference and does not show detailed information. -R or -- recursive compares files in the subdirectory. -S or -- report-identical-files are still displayed if no difference is found. -S or -- starting-file: When comparing directories, compare them from the specified file. -T or -- expand-tabs expand the tab character in the output. -T or -- initial-tab add a tab character before each line for alignment. -U,-U, or -- uniied = are combined to display different file content. -V or -- version displays version information. -W or -- ignore-all-space ignores all space characters. -W or -- width specifies the column width when the-y parameter is used. -X or -- exclude does not compare the files or directories specified in the option. -X or -- exclude-from you can save the file or directory type as a text file, and then specify this text file in =. -Y or -- side-by-side displays similarities and differences of files in parallel. -- Help: displays help. -- When left-column uses the-y parameter, if the content of a row in the two files is the same, only the content of the row is displayed in the left column. -- Suppress-common-lines only show differences when using the-y parameter. 4. use instance: instance 1: compare two file commands: Output: [root @ localhost test3] # diff log2014.log log2013.log 3c3 <2014-03 ---> 2013-038c8 <2013-07 ---> 2013-0811, 12d10 <2013-11 <2013-12 note: the above "3c3" and "8c8" indicate that the contents of log2014.log and log20143log are different in lines 3 and 8th; "11, 12d10 "indicates that the first file contains 11th and 12 more lines than the second file. The normal display format of diff has three prompts: a-addc-changed-delete instance 2: side-by-side output command: diff log2013.log log2014.log-y-W 50 output: [root @ localhost test3] # diff log2014.log log2013.log-y-W 502013-01 2013-012013-02 2013-022014-03 | 2013-032013-04 2013-042013-05 2013- 052013-06 2013-062013-07 2013-072013-07 | 2013-082013-09 2013-092013-10 2013-102013-11 <2013-12 <[root @ localhost test3] # diff log2013.log log2014.log-y-W 50201 3-01 2013-012013-02 2013-022013-03 | 2014-032013-04 2013-042013-05 2013-052013-06 2013-062013-07 2013-072013-08 | 2013-072013-09 2013-092013-10 2013-10> 2013-11> 2013-12: "|" indicates that the content of the first and second files is different. "<" indicates that the latter file has one line less content than the previous file. ">" indicates that the latter file has one line more content than the previous file. 3: command output format: diff log2013.log log2014.log-c output: [root @ localhost test3] # diff log2013.log log2014.log-c *** log2013.log 16:36:26. 000000000 + 0800 --- log2014.log 18:01:54. 000000000 + 0800 *********************** 2013-01 2013-02! 2013-03 2013-04 2013-05 2013-06 2013-07! 2013-08 2013-09 2013-10 --- 2013 ---- 2013-01-02! 2014-03 2013-04 2013-05 2013-06 2013-07! 2013-07 2013-09 2013-10 + 2013-11 + 2013-12 [root @ localhost test3] # diff log2014.log log2013.log-c *** log2014.log 2012-12-07 18:01:54. 000000000 + 0800 --- log2013.log 16:36:26. 000000000 + 0800 ******************* 2013 2013-01-02! 2014-03 2013-04 2013-05 2013-06 2013-07! 2013-07 2013-09 2013-10-2013-11-2013-12 --- 2013 ---- 2013-01-02! 2013-03 2013-04 2013-05 2013-06 2013-07! 2013-08 2013-09 2013-10 [root @ localhost test3] # Note: www.2cto.com compares the two lines at the beginning. here there are three special characters: "+" compares the latter of a file with one more line "-" than the former. "!" Example 4: output command in uniform format: diff log2014.log log2013.log-u output: [root @ localhost test3] # diff log2014.log log2013.log log-u --- log2014.log 18:01:54. 000000000 + 0800 + + log2013.log 16:36:26. 000000000 + 0800 @-2013 + 2013 @ 2014-01 2013-02-2013-03 + 2013-03 2013-04 2013-05 2013-06-07- 07 + 2013-08 2013-09 2013-10-2013-11-2013-12 note: the first part is the basic information of the file: --- log2014.log 18:01:54. 000000000 + 0800 ++ log2013.log 16:36:26. 000000000 + 0800 "---" indicates the file before the change, and "++" indicates the file after the change. In the second part, the change location uses two @ as the beginning and end. @-1st + @ the previous "-" is divided into three parts: the minus sign indicates the first file (that is, log2014.log), and "1" indicates rows, "12" indicates 12 consecutive rows. When combined, it indicates that the first file contains 12 consecutive rows starting from 1st rows. Similarly, "+ 1st" indicates 10 consecutive lines starting from the first row of the second file after the change. Instance 5: compare different folders command: diff test3 test6 output: [root @ localhost test] # diff test3 test6Only in test6: linklog. logOnly in test6: log2012.logdiff test3/log2013.log test6/log2013.log1, 10c1, 3 <2013-01 <2013-02 <2013-03 <2013-04 <2013-05 <2013-06 <2013-07 <2013-08 <2013-09 <2013-10 ---> hostnamebaidu = baidu.com> hostnamesina = sina.com> hostnames = truediff test3/log2014.log test6/log2014.log1, 12d0 <2013-01 <2013-02 <2014-03 <2013-04 <2013-05 <2013-06 <2013-07 <2013-07 <2013-09 <2013- 10 <2013-11 <2013-12Only in test6: log2015.logOnly in test6: log2016.logOnly in test6: log2017.log [root @ localhost test] # Note: instance 6: compare two different files and produce the patch command diff-ruN log2013.log log2014.log> patch. log output: [root @ localhost test3] # diff-ruN log2013.log log2014.log> patch. log [root @ localhost test3] # ll total 12-rw-r -- r -- 2 root 80 12-07 log2013.log-rw-r -- 1 root 96 12-07 log2014.log- rw-r -- 1 root 248 12-07 21:33 patch. log [root @ localhost test3] # cat patc. logcat: patc. log: no file or directory [root @ localhost test3] # cat patch. log --- log2013.log 16:36:26. 000000000 + 0800 + + log2014.log 18:01:54. 000000000 + 0800 @-2013 + 2013 @ 2013-01 2014-02-2013-03 + 2013-03 2013-04 2013-05 2013-06-07- 08 + 2013-07 2013-09 2013-10 + 2013-11 + 2013-12 [root @ localhost test3] # note: instance 7: patch command: output: [root @ localhost test3] # cat log2013.log2013-012013-022013-032013-042013-052013-062013-072013-082013-10 [root @ localhost test3] # patch log2013.log patch. log patching file log2013.log [root @ localhost test3] # [root @ localhost test3] # cat log2013.log 2013-012013-022014-032013-042013-052013-062013-072013-072013-092013- 102013-112013-12 [root @ localhost test3] #
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.