Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the diff command in Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to use the diff command in Linux". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn how to use the diff command in Linux.

Linux common commands the diff command compares the differences between two given files in the simplest case. If you use "-" instead of the "File" parameter, the content to be compared will come from standard input

Diff compares the differences between two given files

Add that the diff command compares the similarities and differences of text files line by line. If the command specifies that a directory comparison is made, files in that directory with the same file name will be compared without any comparison of their subdirectory files.

Syntax diff (option) (parameter) option -: specifies how many lines of text to display. This parameter must be used with the-c or-u parameter; the-an or-- text:diff preset compares text files only line by line;-b or-- ignore-space-change: does not check for differences in space characters;-B or-- ignore-blank-lines: does not check blank lines;-c: displays all contents and marks the differences;-C or-- context: same as executing "- c -" instruction -d or-- minimal: compare in small units using different algorithms;-D or ifdef: the output format of this parameter can be used for pre-processor macros;-e or-- ed: the output format of this parameter can be used for ed's script files;-f or-forward-ed: the output format is similar to ed's script files, but different in the order of the original files -H or-- speed-large-files: speed up when comparing large files;-l or-- ignore-matching-lines: if two files are different on certain lines and both contain the characters or strings specified in the option, the differences between the two files are not displayed;-I or-- ignore-case: do not check the difference in case;-l or-- paginate: leave the results to the pr program for paging -n or-- rcs: display the comparison results in RCS format;-N or-- new-file: when comparing directories, if file An appears only in a directory, the default will display: Only in directory, if file A uses the-N parameter, diff will compare file A with a blank file;-p: if the file is a C language program code file, display the name of the function where the difference is located. -P or-- unidirectional-new-file: similar to-N, but only if the second directory contains files that are not found in the first directory, this file is compared with a blank file;-Q or-- brief: show only differences, not detailed information;-r or-- recursive: compare files in subdirectories;-s or-- report-identical-files: if no differences are found, information is still displayed -S or-- starting-file: when comparing directories, start the comparison from the specified file;-t or-- expand-tabs: expand tab characters on output;-T or-- initial-tab: precede each line with tab characters for alignment;-uLING U or-- unified=: display differences in file contents by merging;-v or-- version: display version information -w or-- ignore-all-space: ignore all space characters;-W or-- width: specify the column width when using the-y parameter;-x or-- exclude: do not compare the file or directory 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: show the similarities and differences of the file side-by-side;-- help: show help;-- left-column: when using the-y parameter, if one line of the two files is the same, then only show the left field;-- suppress-common-lines: show only the differences when using the-y parameter. Parameter file 1: specify the first file to compare

File 2: specify the second file to compare.

By comparing the file "test.txt" in the directory / usr/li with the file "test.txt" in the current directory, enter the following command:

Diff / usr/li test.txt # compares files using the diff directive. After the command above is executed, the differences after comparison are listed in the specified form, as follows:

The letters "a", "d" and "c" denote addition, deletion and modification respectively. "N1" and "N2" represent the line numbers in file 1, and "n3" and "N4" represent the line numbers in file 2.

Note: the above instructions specify the line numbers in different parts of the two files and their corresponding actions. In the output form, each line is followed by several lines that are affected. Where the line that starts with belongs to file 2.

The above is all the contents of the article "how to use diff commands in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report