Created
May 24, 2023 20:24
-
-
Save Sidneys1/d726c2a59f2dcb1be9dfce2dfae0a042 to your computer and use it in GitHub Desktop.
Calculate space savings from deduplication with hardlinks (a la `jdupes -L` or `hardlink`)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find . -type f -links +1 -printf '%i %s\n' | # Find all files with more than one link (hardlinks), and print the inode and size | |
sort | uniq -c | # Sort and unique, prefixing the number of repeated lines. | |
# Since all hardlinks point to the same inode, the count will be the number of | |
# files pointing to each unique inode. | |
awk '{print ($1-1)*$3}' | # Multiply the first number minus one (redundant hardlinks) by the second number (size). | |
awk '{n+=$1}; END{print n}' | # Sum the results. | |
numfmt --to=iec-i # Convert to an IEC i-size. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment