trimtrees - traverse directories, find identical files, replace with hard links
trimtrees.pl OPTIONS directory... OPTIONS: --maxlinks N limit the amount of links per file
Traverse all directories named on the command line, compute MD5 checksums and find files with identical MD5. IF they are equal, do a real comparison if they are really equal, replace the second of two files with a hard link to the first one.
Special care is taken to cope with Too many links error conditions. The inode that is overbooked in such a way, is taken out of the pool and replaced with the another one such that the minimum of files needed is kept on disk.
Too many links
The --maxlinks option can be used to reduce the linkcount on all files within a tree, thus preparing the tree for a subsequent call to cp -al. This operation can be thought of the reverse of the normal trimtrees operation (--maxlinks=1 produces a tree without hard links).
--maxlinks
cp -al
SIGINT is caught and the script stops as soon as the current file is finished.
The whole idea of replacing identical files with hard links has inherent dangers. Once two files have turned into one inode other processes may accidentally change both although they intend to alter only one. Please consider if this can happen in your environment.
To install Perl::Repository::APC, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perl::Repository::APC
CPAN shell
perl -MCPAN -e shell install Perl::Repository::APC
For more information on module installation, please visit the detailed CPAN module installation guide.