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

The usage of the Linux basic command cmp

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

Share

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

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!

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