Get the App
SLTechnology News&Howtos  ›  Servers  › 

The usage of the Linux basic command cmp

Shulou Source: shulou.com Published: 2022-06-01 12:38:42 10月03日 Update

This article mainly explains "the usage of the Linux basic command cmp". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the usage of the basic Linux command cmp.

Cmp

Compare the differences between the two files in bytes, but do not save the results of the operation. The Cmp instruction only sets the relevant flag bits based on the result, which is often followed by a conditional jump instruction. The scope of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora.

1. Grammar

Cmp [OPTION]... FILE1 [FILE2 [SKIP1 [SKIP2]

2. List of options

Option

Description

-v |-- version

Display command version information

-- help

Show help documentation

-b |-- print-bytes

Output different bytes

-I num |-- ignore-initial=num

Skip the first num bytes

-I num1 num2 |-- ignore-initial=num1:num2

The first file skips num1 bytes and the second file skips num2 bytes

-l |-- verbose

Output the byte sequence number of the difference, as well as the value of this byte

-n LIMIT |-- bytes=LIMIT

Compare LIMIT bytes at most

-s |-- quiet |-- silent

Do not output; only output exit status

3. Examples

1) Direct comparison

[root@localhost weijie] # diff-y 1.c 2.c / / first use diff to see the differences

Asd | ase

Sdf | sdd

Dfg dfg

[root@localhost weijie] # cmp 1.c 2.c / / start comparison

1.c 2.c differ: byte 3, line 1 / / shows only the first difference, the first line, the third byte

2) use the option-b to show the different bytes

[root@localhost weijie] # cmp-b 1.c 2.c

1.c 2.c differ: byte 3, line 1 is 144d 144e / / shows different places, the first file is d and the second file is e. But there's only the first difference here.

3) use the option-l to show all the differences

[root@localhost weijie] # cmp-lb 1.c 2.c / / uses both l and b options

3 144 d 145 e / / the first difference

7 146 f 144 d / / the second difference

At this point, I believe you have a deeper understanding of "the use of the Linux basic command cmp". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Different byte command file output basic instruction content result learning practical deeper one line two information interest only at the same time place instance Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Docker MariaDB Huawei Linux