Skip to content

Instantly share code, notes, and snippets.

@gfldex
Created October 5, 2016 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfldex/865852d35e17760ace55c19178cf79bf to your computer and use it in GitHub Desktop.
Save gfldex/865852d35e17760ace55c19178cf79bf to your computer and use it in GitHub Desktop.
use v5.012;
use strict;
use warnings;
my %seen_ino;
sub recurse {
my $rel_path = shift @_;
opendir my $dh, $rel_path || warn "Can not open $ENV{HOME}: $!" && return;
while (readdir $dh) {
# stat will resolve the symlink
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks)
= stat("$rel_path/$_");
# say($dev, ' ', $ino, ' ', "$rel_path/$_") if -l "$rel_path/$_";
next if $_ eq '.' || $_ eq '..';
if ( -d "$rel_path/$_" ) {
my $how_often = $seen_ino{"$dev+$ino"};
$how_often++;
if ( $how_often > 1 ) {
say "seen $rel_path/$_ already $how_often times";
}
$seen_ino{"$dev+$ino"} = $how_often;
}
recurse("$rel_path/$_") if -d "$rel_path/$_";
}
}
recurse $ENV{HOME};
# say "dupes:";
# while ( my ($key, $value) = each %seen_ino ) {
# say $key if $value > 1
# };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment