Get the App
SLTechnology News&Howtos  ›  Servers  › 

What are the differences between using cmp and comm commands in Linux systems

Shulou Source: shulou.com Published: 2022-06-01 08:53:42 11月12日 Update

This article mainly introduces "what are the differences between using cmp and comm commands in Linux systems". In daily operation, I believe that many people have doubts about the differences between cmp and comm commands in Linux systems. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "what are the differences between cmp and comm commands in Linux systems?" Next, please follow the editor to study!

Cmp

Cmp command: compare any two types of files, and output the results to standard output. The same default file is not output, but different file output differences.

Necessary parameters

-c displays different information

-l list all the different information

-s error message does not prompt

Select parameters

-I specify the number of characters

-v displays version information

-- help displays help information

[return value of function]

0: the file is the same

1: the files are different.

> 1: an error occurred

Example:

The code is as follows:

[root@localhost www] # cmp test1.rb test.rb # compare the differences between the two files

Test1.rb test.rb differ: byte 1, line 1

[root@localhost www] # cmp-l test1.rb test.rb # shows all the differences

1 160 162

2 165 145

3 164 161

4 163 165

5 40 151

6 42 162

7 150 145

8 145 40

9 153 42

10 153 155

11 153 171

12 42 163

13 12 161

Cmp: EOF on test1.rb

Comm

Comm-compare two sorted files line by line

Compare the sorted files LEFT_FILE and RIGHT_FILE line by line.

-1

Mask lines (or contents) in the file on the left (LEFT_FILE) that are different from the file on the right

-2

Mask lines (or contents) in the right file (RIGHT_FILE) that are different from the left file

-3

Mask the same line (or content) in both files

(translation note: the original text is "different lines", suspected to be incorrect)

-l

It is considered that the input data is sorted according to the current locale (the-l option should be provided for sort).

-- help

Display help information and then end

-- version

Display version information, and then end

Example:

The code is as follows:

[root@localhost www] # comm test.rb test1.rb # compare two files

At this point, the study on "what is the difference between using cmp and comm commands in Linux systems" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Files information different commands system learning help output same two content code parameters right more version error sorting practical necessary Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Xiaomi Shulou Information MySQL Redmi