Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You might want to try the ol' <a href="http://perldoc.perl.org/File/Find.html" rel="nofollow">File::Find</a>. It's not my favorite module. (It is just funky in the way it works), but for your purposes, it allows you to easily find all files in two directories, and compare them. Here's a brief example:</p> <pre><code>use strict; use warnings; use feature qw(say); use Digest::MD5::File qw(file_md5_hex); use File::Find; use constant { DIR_1 =&gt; "/usr/foo", DIR_2 =&gt; "/usr/bar", }; my %dir_1; my %dir_2; find ( sub { if ( -f $File::Find::name ) { $dir_1{$File::Find::name} = file_md5_hex($File::Find::name); } else { $dir_1($file::Find::name} = "DIRECTORY!"; } }, DIR_1); find ( sub { if ( -f $File::Find::name ) { $dir_2{$File::Find::name} = file_md5_hex($File::Find::name); } else { $dir_2($file::Find::name} = "DIRECTORY!"; } }, DIR_2); </code></pre> <p>This will create two hashes keyed by the file names in each directory. I used the <a href="http://search.cpan.org/~dmuey/Digest-MD5-File-0.07/File.pm" rel="nofollow">Digest::MD5::File</a> to create a MD5 checksum. If the checksum between the two files differ, I know the files differ (although I don't know where).</p> <p>Now you have to do three things:</p> <ol> <li>Go through <code>%dir_1</code> and see if there's an equivalent key in <code>%dir_2</code>. If there is not an equivalent key, you know that a file exists in <code>%dir_1</code> and not <code>%dir_2</code>.</li> <li>If there an equivalent key in each hash, check to see if the md5 checksums agree. If they do, then, the files match. If they don't they differ. You can't say where they differ, but they differ.</li> <li>Finally, go through <code>%dir_2</code> and check to see if there's an equivalent key in <code>%dir_1</code>. If there is, do nothing. If there isn't, that means there's a file in <code>%dir_1</code> that's not in <code>%dir_2</code>.</li> </ol> <p>Just a word of warning: The keys int these two hashes <strong><em>won't match</em></strong>. You'll have to transform one to the other when doing your compare. For example, you'll have two files as:</p> <pre><code>/usr/bar/my/file/is/here.txt /usr/foo/my/file/is/here.txt </code></pre> <p>As you can see, <code>my/file/is/here.txt</code> exist in both directories, but in my code, the two hashes will have two different keys. You could either fix the two subroutines to strip the directory name off the front of the files paths, or when you do your comparison, transform one to the other. I didn't want to run through a full test. (The bit of code I wrote works in my testing), so I'm not 100% sure what you'll have to do to make sure you find the matching keys.</p> <p>Oh, another warning: I pick up all entries and not just files. For directories, I can check to see if the hash key is equal to <code>DIRECTORY!</code> or not. I could simply ignore everything that's not a file.</p> <p>And, you might want to check for special cases. Is this a link? Is it a hard link or a soft link? What about some sort of <em>special file</em>. That makes things a bit more complex. However, the basics are here.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload