Cmp

Cmp


Linux cmp command

  • On Unix-like operating systems, the cmp command is used to compare two files byte by byte. If a difference is found, it reports the byte and line number where the first difference is found. If no differences are found, by default, cmp returns no output.

  • This document covers the GNU/Linux version of cmp.

    Syntax

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

    Options

  • The optional SKIP1 and SKIP2 specify the number of bytes to skip at the beginning of each file (zero by default).

    SKIP values may be followed by the following multiplicative suffixes:

    kB

    kilobytes

    1000

    K

    kibibytes

    1024

    MB

    megabytes

    1,000,000

    M

    mebibytes

    1,048,576

    GB

    gigabytes

    1,000,000,000

    G

    gibibytes

    1,073,741,824

    ...and so on for T, P, E, Z, Y.

  • If a FILE is specified as '-' or not specified, data is read from standard input. cmp's exit status is 0 if inputs are the same, 1 if different, or 2 if the program encounters a problem.

    Additional options:

    -b, --print-bytes

    Print differing bytes.

    -i, --ignore-initial=SKIP

    Skip first SKIP bytes of both files.

    -i, --ignore-initial=SKIP1:SKIP2

    Skip first SKIP1 bytes of FILE1 and first SKIP2 bytes of FILE2.

    -l, --verbose

    Output byte numbers and differing byte values.

    -n, --bytes=LIMIT

    Compare at most LIMIT bytes.

    -s, --quiet, --silent

    Suppress all normal output.

    --help

    Display a help message and exit.

    -v, --version

    Output version information and exit.

    Examples

    cmp file1.txt file2.txt

  • Compares file1 to file2, reading each file byte-by-byte and comparing them until one of the byte pairs is not equal. When a difference is found, it will output the location in the file where the difference was found, and exit. Example output:

    file.txt file2.txt differ: char 1011, line 112

    Related commands

  • comm — Compare two sorted files line by line.

  • diff — Identify the differences between
    two files.


    What is an Operating System? » Computer Shortcut Keys and their Functions » Keyboard Function Keys » Computer Basics - Hardware - Software - Parts

    Short Stories for Kids - Moral Stories – English Short Stories for Children - Moral Stories for Kids - Stories for Kids - Funny Story for Kids - Scary Stories for Kids - Really Funny Short Stories - Bedtime Stories
    Proverb Stories
    Powerful Motivational Quotes for Students » Success Quotes » English Short Stories for Kids

    Cabin Crew Jobs & Career Advice » Secretary Job Description » Receptionist Job Description » Top 100 Interview Questions and Answers » How to Prepare for an Interview » How to Write a CV » How to Choose a Career » Computer Shortcut Keys and their Functions

    Scholarships in Australia » Scholarships in Austria » Scholarships in Belgium » Scholarships in Canada » Scholarships in Germany » Scholarships in Ireland » Scholarships in Italy » Scholarships in Japan » Scholarships in Korea » Scholarships in Netherlands » Scholarships in Switzerland » Scholarships in UK » Scholarships in USA

    Scholarships for Study in Africa » Scholarships for African Students » Undergraduate Scholarships » African Women Scholarships & Grants Scholarships for Study in Africa » Scholarships for African Students » Undergraduate Scholarships » African Women Scholarships & Grants Scholarships for Study in Africa » Scholarships for African Students » Undergraduate Scholarships » African Women Scholarships & Grants Short Stories for Kids - Moral Stories – English Short Stories for Children - Moral Stories for Kids - Stories for Kids - Funny Story for Kids - Scary Stories for Kids - Really Funny Short Stories - Bedtime Stories
    Proverb Stories
    Powerful Motivational Quotes for Students » Success Quotes »Scholarships in UK » Scholarships in USA Scholarships in UK »

  • Click here to post comments

    Join in and write your own page! It's easy to do. How? Simply click here to return to Computer Basics FAQ.