1

It is relatively common to use a "hard link tree" to create a second backup of a folder that is effectively just a copy of the files that have changed since the original backup.

For example, rsync has a command line option --link-dest to achieve this.

My question is whether there is an easy way to see the extra disk space used by such a "hard link tree"?

Because the hard links are the same file, just performing du on the new tree will show the total size of all the files, including the ones that are hard links, and thus share the disk space of the original files.

  • Do you mean that you want to see the disk space used by files with only one link (i.e they are not available anywhere else in the filesystem)? If not, what do you actually want to measure? – roaima Nov 17 '18 at 15:13
  • @roaima - sort of. I was wanting to find the extra space used by a second backup, excluding the space used by the first - i.e. files within the second backup that don't also have a hard linked version in the first backup. As below, I discovered after asking the question that du implicitly does what I need – Michael Firth Nov 21 '18 at 11:38
  • Yes, du will do what you've described – roaima Nov 21 '18 at 17:54
1

After some more experimentation, it seems du is more "clever" than I expected.

If you give it the two trees as arguments, then it displays the size of the second tree relative to the first:

du -sh backup-Jan backup-Feb
242G    backup-Jan
24G     backup-Feb

Where if you just give it the second tree, it shows the whole size:

du -sh backup-Feb
245G    backup-Feb

And if you give the arguments in reverse it does the expected thing and shows the full size for the newer backup, and the relative size for the older backup

du -sh backup-Feb backup-Jan
245G    backup-Feb
21G     backup-Jan

I assumed this was going to be a much harder thing to find the answer for!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.