Issue: "ipfs add" and "ipfs files write" the difference between the two?

  1. When I use commands:
 ipfs add test.mp4

hash value: QmS2sz7WNaVMDbbuBdzLVNVXwtWsNyNs3S4KjFaYY87aAV

  1. When I use commands:
cat test.mp4 | ipfs files write --create /test/test.mp4

hash value: QmazXU4S74VbLjqLouNMuJhKnWp5XKnyp7qqLnRmD3WLgu

Obviously the two hash values are different,But when I used “ipfs get $hashValue” to download the files, I found they were identical

My question:

  1. Why are they different?
  2. Why are there two ways to add files, and the difference between them?

All these problems have been bothering me, but I still haven’t found the result. Please help me, thanks.

mod edit: I’ve imported the text of this post from for convenience.

Why are they different?

When importing files, IPFS chunks the files into small pieces and then builds a merkletree on top of these chunks. By default, ipfs add ... generates a balanced merkletree while ipfs files write uses a merkletree optimized for appending (IIRC).

Why are there two ways to add files, and the difference between them?

There are two commands because:

  • ipfs add just adds the file to IPFS but doesn’t give it a name.
  • ipfs files write --create puts the file into a virtual filesystem we call MFS (mutable file system). This is often more convenient for managing files (see:

Really, we should eventually combine these commands into a more unified API (ideally, one that uses MFS by default). However, that hasn’t been a priority.

Thank you for your answer.I think both commands are fine, But if the “ipfs files write” command can be improved to:

ipfs files add test.mp4 /test/test.mp4
ipfs files add -r ./* /test/

Instead of adding one file at a time:

cat test.mp4 | ipfs files write --create /test/test.mp4

Thanks again to IPFS for being the best storage I’ve had so far.

I agree. Note: You can currently run ipfs files cp /ipfs/$(ipfs add -Q test.mp4) /test/test.mp4.