One linux Command (36) every day: diff command

Source: Internet
Author: User
Tags log log one more line touch command

One linux Command every day (36): diff command link: One linux Command every day (1): ls command http://www.bkjia.com/ OS /210210/163049.html#linuxlinuxcommand every day (2): cd command serial (3 ): pwd command Export (4): mkdir command http://www.bkjia.com/ OS /201210/1620.3.html#a linuxcommand every day (5): rm command Export (6): rmdir command http://www.bkjia.com/ OS /201210/164017. Html; one linux Command every day (7): mv command running (8): cp command http://www.bkjia.com/ OS /201210/163164.html#a linuxcommand every day (9): touch command running (10): cat command running (11 ): nl command http://www.bkjia.com/ OS /201211/165990.htmla linuxcommand every day (12): more command http://www.bkjia.com/ OS /201211/165994.htmllinuxcommand every day (13): Less command restart (14): head command http://www.bkjia.com/ OS /201211/166191.htmllinuxcommand every day (15): tail command restart (16): which command restart (17): whereis command restart (18 ): locate command http://www.bkjia.com/ OS /201211/168895.htmla linuxcommand every day (19): find command overview h Ttp: // timeout (20): exechttp of the find command: // www.bkjia.com/ OS /201211/168901.htmllinuxcommand every day (21): xargshttp of the find command: // timeout (22 ): detailed description of the parameters of the find command: http://www.bkjia.com/ OS /201211/168912.htmla linuxcommand every day (23): Linux directory structure (24): Linux file type and extension (2 5): linux File Attribute explanation example (26): Use SecureCRT to upload and download files. Example (27): linux chmod command example (28): tar command http://www.bkjia.com/ OS /201212/172.161.html A linuxcommand every day (29 ): chgrp command http://www.bkjia.com/ OS /201212/172983.htmla linuxcommand every day (30): chown command http://www.bkjia.com/ OS /201212/173239.htmlone per day Linux Command (31):/etc/group file detailed explanation http://www.bkjia.com/ OS /201212/174429.htmlevery day a linuxcommand (32): gzip command running (33): df command running (34): du command running (35 ): ln command http://www.bkjia.com/ OS /201212/174993.html diff command is a very important tool on linux, used to compare the content of the file, especially compare two versions of different files to find the change. 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] #
 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.