Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You're about to be very surprised!

  echo old > a
  ln a b
  echo new > a  
  cat a b                   # prints "new" and "new"
Some programs like GNU sed [1] do create new inodes, but that is a property of the application, not the filesystem:

  echo old > a
  ln a b
  sed -i 'c new' a
  cat a b                   # prints "new" and "old"
With reflinks in a CoW filesystem the inodes are different from the start, but share the same underlying blocks:

  echo old > a
  cp --reflink=always a b
  ls -i a b                 # prints different inodes
  echo new > a
  cat a b                   # prints "new" and "old"
[1] https://www.gnu.org/software/sed/manual/html_node/Command_00...


Cool, I love surprises :D

Thanks for examples and especially the doc link. I don't normally use hard links, and for some reason was sure that's how they behave.

Maybe my belief indeed stemmed from observing software which overwrites opened file with a new copy.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: