Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Here's an excerpt of the commands I ran as I split and then cat a file:

sh-3.2# split -b 600m bt4-final.iso 

sh-3.2# ls -hal
total 6132096
drwxr-xr-x   6 root   staff   204B Jan 12 19:59 .
drwxr-xr-x  13 alien  staff   442B Jan 12 19:54 ..
-rw-r--r--   1 root   staff   1.5G Jan 12 19:56 bt4-final.iso
-rw-r--r--   1 root   staff   600M Jan 12 19:58 xaa
-rw-r--r--   1 root   staff   600M Jan 12 19:59 xab
-rw-r--r--   1 root   staff   297M Jan 12 19:59 xac

sh-3.2# cat $(ls -t x*) > bt4-final-reasembled.iso

sh-3.2# ls
bt4-final-reasembled.iso    xaa          xac
bt4-final.iso               xab

sh-3.2# md5 bt4*
MD5 (bt4-final-reasembled.iso) = edd4f24f3abcabb8a447a69eaa30ff39
MD5 (bt4-final.iso) = af139d2a085978618dc53cabc67b9269

Why is it that the MD5 hash is different for what is essentially the same file?

share|improve this question
4  
Because MD5 still has a small chance of not generating a collision :P –  silky Jan 13 '10 at 1:55
1  
I'd like to see the output of 2 commands: 1. ls -l bt4* 2. cmp bt4* –  Laurence Gonsalves Jan 13 '10 at 1:59
add comment

migrated from stackoverflow.com Jan 13 '10 at 9:16

This question came from our site for professional and enthusiast programmers.

6 Answers

You're catting the files together in the wrong order, owing to the unnecessary ls -t.

cat x* > out.iso would do just fine and give the correct output. POSIX guarantees that globbing will give you files in sorted order.

share|improve this answer
    
+1 I just noticed the -t, but you beat me to answering. –  Laurence Gonsalves Jan 13 '10 at 2:01
add comment

You were reconstituting the files in the wrong order. With the use of ls -t, files are listed newest (i.e., last split chunk, in your case) first.

share|improve this answer
add comment

Are you sure you are combining them in the same order? If you combine them in a different order, you should certainly expect the MD5 sum to be different.

If you combined them in the same order, the bits would be the same, and you would get the same md5 sum. If the bits are not the same, it probably means your RAM is bad. See memtest86.

share|improve this answer
    
yes, maybe "ls -t" is not so good. should be ordered alphabetically. –  Thilo Jan 13 '10 at 2:00
add comment

I guess, its because of ls -t, you are sorting by time, so last one before first in resamble file

share|improve this answer
add comment

Because you're not putting them back together in the same order that they started in. You're right, if you reassemble them correctly, the md5sum should match. Here's a trivial example:

$ cat > xaa
This is the first file
$ cat > xab
This is the second file
$ cat > xac
This is the third file.
$ cat $(ls -t x*) > final.txt
$ cat final.txt
This is the third file.
This is the second file
This is the first file

Try this:

$ cat x* > good.txt
$ cat good.txt
This is the first file
This is the second file
This is the third file.
share|improve this answer
add comment

Somehow some bits got corrupt, got reordered, got added, or got removed in the process of splitting and rejoining.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.