Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 242487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:50:30+00:00 2026-05-11T20:50:30+00:00

Suppose I have two files, A and B, and that lengthOf(A) < lengthOf(B). Is

  • 0

Suppose I have two files, A and B, and that lengthOf(A) < lengthOf(B). Is there a unix utility to tell if file B duplicates file A for the first lengthOf(A) bytes?

If I do “diff A B”, the output will be all the ‘extra stuff’ in the B file, which misses the point; I don’t care what else might be in file B.

If I do “comm A B”, then I have to visually inspect that nothing turns up in the column for ‘only in A’. This can be difficult when lengthOf(B) >> lengthOf(A), though I suppose it could be tamed with grep.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:50:31+00:00Added an answer on May 11, 2026 at 8:50 pm

    This seems much better than creating temporary file:

    SIZE=`stat -c %s filea`
    cmp -s -n $SIZE filea fileb # -s for silence
    

    Check the exit status to see whether the first bytes of those files are indeed equal.

    Update: as per request of xk0der, here is a longer example:

    wormhole:tmp admp$ echo -n "fooa" > one # -n to supress newline
    wormhole:tmp admp$ echo -n "foobc" > two
    wormhole:tmp admp$ SIZE=`stat -c %s one`
    wormhole:tmp admp$ echo $SIZE
    4
    wormhole:tmp admp$ (cmp -s -n $SIZE one two && echo "equal") || echo "not equal"
    not equal
    wormhole:tmp admp$ echo -n "fooac" > two # first 4 bytes are equal now
    wormhole:tmp admp$ (cmp -s -n $SIZE one two && echo "equal") || echo "not equal"
    equal
    

    Also, in MacOS X you have to use:

    SIZE=`stat -f %z filename`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have two XML files. First XML File: <?xml version=1.0?> <AccessRequest xml:lang=en-US> <AccessLicenseNumber>Your_License</AccessLicenseNumber>
Suppose I have two lists that holds the list of source file names and
Suppose I have two columns in a table that represents a graph, the first
I have a jar file that contains two files in the root tbs.jar -parser.dat
Suppose that you have two huge files (several GB) that you want to concatenate
Suppose I have two classes that both contain a static variable, XmlTag. The second
Suppose you have two linked servers called Local and Remote respectively. Is there a
Suppose I have two tables that are linked (one has a foreign key to
Suppose I have two files containing styles, a.css and b.css. I import them into
Suppose I have two .h files: A.h and B.h. Moreover, A.h includes B.h itself:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.