ArticleslgStudy

science

Cmp (Unix)

Cmp (Unix) is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Cmp (Unix) rather than just read about it. In short: cmp is a shell command that compares two files of any type and reports differences. By default, it outputs nothing if the files match.

Cmp (Unix) — main illustration
Cmp (Unix) — illustration

Key takeaways

  • Cmp (Unix) belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Cmp (Unix) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Cmp (Unix) from memory before moving on to harder problems.

Reference excerpt

cmp is a shell command that compares two files of any type and reports differences. By default, it outputs nothing if the files match. If they differ, it reports the byte and line number of the first difference. The exit code can be used programmatically since it is 0 if the files match, 1 if the files differ or 2 if comparison fails (i.e. inaccessible or missing argument). The command is available on Unix-like systems, OS-9, IBM i and Windows (via UnxUtils). The command first appeared in Version 1 Unix. It is part of the X/Open Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and the Single Unix Specification. The implementation in GNU coreutils was written by Torbjorn Granlund and David MacKenzie.

Use Command line options include:

Operands that are byte counts are decimal by default, but may be preceded by '0' for octal and '0x' for hexadecimal. A byte count can be followed by a suffix to specify a multiple of that count; in this case an omitted integer is understood to be 1. A bare size letter, or one followed by 'iB', specifies a multiple using powers of 1024. A size letter followed by 'B' specifies powers of 1000 instead. For example, '-n 4M' and '-n 4MiB' are equivalent to '-n 4194304', whereas '-n 4MB' is equivalent to '-n 4000000'. This notation is upward compatible with the SI prefixes for decimal multiples and with the IEC 60027-2 prefixes for binary multiples.

Example

See also Comparison of file comparison tools List of POSIX commands

References

External links

cmp: compare two files – Shell and Utilities Reference, The Single UNIX Specification, Version 5 from The Open Group Comparing and Merging Files: Invoking cmp The section of the manual of GNU cmp in the diffutils free manual.

Worked examples

Example 1 — a first encounter with Cmp (Unix)

Start with the simplest possible case. Write down what Cmp (Unix) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Cmp (Unix) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Cmp (Unix) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Cmp (Unix)

In research
Cmp (Unix) appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Cmp (Unix) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Cmp (Unix) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Free file comparison tools, IBM i Qshell commands, Inferno (operating system) commands, so understanding it makes those chapters shorter.
In everyday life
Look for Cmp (Unix) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Cmp (Unix)” →

How to study Cmp (Unix) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Cmp (Unix) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Cmp (Unix) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Cmp (Unix) in simple terms?

cmp is a shell command that compares two files of any type and reports differences. By default, it outputs nothing if the files match.

Why does Cmp (Unix) matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Cmp (Unix)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Cmp (Unix).

Tags

  • Free file comparison tools
  • IBM i Qshell commands
  • Inferno (operating system) commands
  • Plan 9 commands
  • Standard Unix programs
  • Unix SUS2008 utilities

Keep exploring