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

Use the cmp command of linux to compare the differences between the two files

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article uses easy-to-understand examples to introduce the use of linux cmp command to compare whether there are differences between the two files, the code is very detailed, interested friends can refer to, hope to be helpful.

The cmp command is used to compare two files of any type. If the two files are the same, no information is output by default. If the two files are different, the character and column number of the first difference will be output, and the result will be output to standard output.

If no file name is specified or given a file name of "-", the cmp command reads data from the standard input device.

Syntax format: cmp [parameters] [file] [file]

Commonly used parameters: coach

-- help display help-v/--version display version information-s/--quit/--silent does not display error messages-l/--verbose marks all differences-i/--ignore-initial specifies a number-c/--print-chars displays the corresponding character in addition to the decimal code that indicates the difference

Reference example

Compare the files "tempfile" and "tempfile1" (when the two files are the same, no information is displayed, the two files are different):

[root@linuxcool ~] # cmp tempfile tempfile1

Tempfile tempfile1 differ:byte 1, line 1

Compare the files "tempfile" and "tempfile1" with no error message:

[root@linuxcool] # cmp-s tempfile tempfile1

Compare the files "tempfile" and "tempfile1" to indicate all the differences:

[root@linuxcool ~] # cmp-l tempfile tempfile1

1 12 151

2 151 167

8 167 12

Cmp: EOF on tempfole1 after byte8

Compare the files "tempfile" and "tempfile1" and specify a number:

[root@linuxcool] # cmp-I 2 tempfile tempfile1

Tempfile tempfile1 differ:byte 6, line 1

Compare the files "tempfile" and "tempfile1" to show the corresponding characters in addition to the decimal codes that indicate the differences:

[root@linuxcool ~] # cmp-c tempfile tempfile1

Tempfile tempfile1 differ:byte 1, line 1 is 12'J 151I

On the use of linux's cmp command to compare whether there are differences between the two files is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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

Servers

Wechat

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

12
Report