The second thing you said is exactly correct. The file contents only exist once on disk. A hard link is an extra reference, which costs very little space - the size of a directory entry, which is the length of the filename plus a few bytes.
I don't know if this applies to OSX, but in the version of GNU coreutils I have handy, du
is aware of hard links, so you can use it to get an accurate report of the total size of a set of files. If it finds multiple links to a file, it only adds it to the total once. ls -l
on the other hand does the wrong thing and adds everything it sees in a directory for its total
line.
$ ls -sl
total 296
296 -rw-r--r-- 1 user group 300324 Feb 17 19:08 f1
$ du
296 .
$ ln f1 f2
$ ls -sl
total 592
296 -rw-r--r-- 2 user group 300324 Feb 17 19:08 f1
296 -rw-r--r-- 2 user group 300324 Feb 17 19:08 f2
$ du
296 .
$ cp f1 f3
$ ls -sl
total 888
296 -rw-r--r-- 2 user group 300324 Feb 17 19:08 f1
296 -rw-r--r-- 2 user group 300324 Feb 17 19:08 f2
296 -rw-r--r-- 1 user group 300324 Feb 17 19:08 f3
$ du
592 .
$
The ultimate demonstration would be to create a huge file, more than half the size of the disk. Then see how many hard links you can create to it. Should be quite a lot.