Forrest logo
back to the cmp tool

cmp:tldr:45e91

cmp: Output char and line number of the first difference between two files.
$ cmp ${filename1} ${filename2}
try on your machine

The command "cmp ${filename1} ${filename2}" is used to compare the contents of two files ${filename1} and ${filename2}.

Here's how it works:

  1. The "cmp" command is the main command being used here. It stands for "compare".
  2. ${filename1} and ${filename2} are variables representing the names or paths of the two files that you want to compare. The variables should be replaced with the actual filenames or paths when using the command.
  3. The command compares the contents of ${filename1} and ${filename2} byte by byte.
  4. If the files are identical, there is no output or error messages.
  5. If the files differ, the command outputs the byte and line numbers where the first difference occurred, as well as the differing byte values.
  6. The command can be used to check if two files are identical or to find the differences between them.

Example: Suppose you have two files named "file1.txt" and "file2.txt". To compare their contents, you would use the command: cmp file1.txt file2.txt

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the cmp tool