Created
October 5, 2016 17:36
-
-
Save gfldex/865852d35e17760ace55c19178cf79bf to your computer and use it in GitHub Desktop.
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
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