Date: Fri, 5 May 2023 05:06:25 +0100 From: Kaya Saman <kayasaman@optiplex-networks.com> To: Paul Procacci <pprocacci@gmail.com> Cc: freebsd-questions@freebsd.org Subject: Re: Tool to compare directories and delete duplicate files from one directory Message-ID: <b4ac4aea-a051-fbfe-f860-cd7836e5a1bb@optiplex-networks.com> In-Reply-To: <CAFbbPujbyPHm2GO%2BFnR0G8rnsmpA3AxY2NzYOAAXetApiF8HVg@mail.gmail.com> References: <9887a438-95e7-87cc-a162-4ad7a70d744f@optiplex-networks.com> <CAFbbPugfhXGPfscKpx6B0ue=DcF_qssL6P-0GgB1CWKtm3U=tQ@mail.gmail.com> <344b29c6-3d69-543d-678d-c2433dbf7152@optiplex-networks.com> <CAFbbPuiNqYLLg8wcg8S_3=y46osb06%2BduHqY9f0n=OuRgGVY=w@mail.gmail.com> <ef0328b0-caab-b6a2-5b33-1ab069a07f80@optiplex-networks.com> <CAFbbPujUALOS%2BsUxsp=54vxVAHe_jkvi3d-CksK78c7rxAVoNg@mail.gmail.com> <7747f587-f33e-f39c-ac97-fe4fe19e0b76@optiplex-networks.com> <CAFbbPuhoMOM=wp26yZ42e9xnRP%2BtJ6B30y8%2BBa3eCBh2v66Grw@mail.gmail.com> <fd9aa7d3-f6a7-2274-f970-d4421d187855@optiplex-networks.com> <CAFbbPujpPPrm-axMC9S5OnOiYn2oPuQbkRjnQY4tp=5L7TiVSg@mail.gmail.com> <eda13374-48c1-1749-3a73-530370934eff@optiplex-networks.com> <CAFbbPujbyPHm2GO%2BFnR0G8rnsmpA3AxY2NzYOAAXetApiF8HVg@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 5/5/23 04:36, Paul Procacci wrote: > #!/usr/bin/env perl > > use strict; > use warnings; > > sub msgDie > { > =C2=A0 my ($ret) =3D shift; > =C2=A0 my ($msg) =3D shift // "$0 dir_base dir\n"; > =C2=A0 print $msg; > =C2=A0 exit($ret); > } > > msgDie(1) unless(scalar @ARGV eq 2); > > my $base =3D $ARGV[0]; > my $dir =C2=A0=3D $ARGV[1]; > > msgDie(1, "base directory doesn't exist\n") unless -d $base; > msgDie(1, "source directory doesn't exist\n") unless -d $dir; > > opendir(my $dh, $dir) or msgDie("Unable to open directory: $dir\n"); > while(readdir $dh) > { > =C2=A0 next if($_ eq '.' || $_ eq '..'); > =C2=A0 next if(! -f "$base/$_"); > > =C2=A0 my ($ref) =3D (stat("$base/$_"))[7]; > =C2=A0 my ($src) =3D (stat("$dir/$_"))[7]; > =C2=A0 unlink("$dir/$_") if($ref =3D=3D $src); > } To start with this is the directory structure: =C2=A0ls -lhR /tmp/test1 total 1 drwxr-xr-x=C2=A0 2 root=C2=A0 wheel=C2=A0=C2=A0=C2=A0=C2=A0 3B May=C2=A0 = 5 04:57 dupdir1 drwxr-xr-x=C2=A0 2 root=C2=A0 wheel=C2=A0=C2=A0=C2=A0=C2=A0 3B May=C2=A0 = 5 04:57 dupdir2 /tmp/test1/dupdir1: total 1 -rw-r--r--=C2=A0 1 root=C2=A0 wheel=C2=A0=C2=A0=C2=A0=C2=A0 8B Apr 30 03:= 17 dup /tmp/test1/dupdir2: total 1 -rw-r--r--=C2=A0 1 root=C2=A0 wheel=C2=A0=C2=A0=C2=A0=C2=A0 7B May=C2=A0 = 5 03:23 dup1 ls -lhR /tmp/test2 total 1 drwxr-xr-x=C2=A0 2 root=C2=A0 wheel=C2=A0=C2=A0=C2=A0=C2=A0 3B May=C2=A0 = 5 04:56 dupdir1 drwxr-xr-x=C2=A0 2 root=C2=A0 wheel=C2=A0=C2=A0=C2=A0=C2=A0 3B May=C2=A0 = 5 04:56 dupdir2 /tmp/test2/dupdir1: total 1 -rw-r--r--=C2=A0 1 root=C2=A0 wheel=C2=A0=C2=A0=C2=A0=C2=A0 4B Apr 30 02:= 53 dup /tmp/test2/dupdir2: total 1 -rw-r--r--=C2=A0 1 root=C2=A0 wheel=C2=A0=C2=A0=C2=A0=C2=A0 7B Apr 30 02:= 47 dup1 So what I want to happen is the script to recurse from the top level=20 directories test1 and test2 then expected behavior should be to remove=20 file dup1 as dup is different between directories. I ran the script and again it didn't produce any output? ./test.pl /tmp/test1 /tmp/test2 I'm not sure if I need any other perl module? It is installed: p5-ExtUtils-Config-0.008_1=C2=A0=C2=A0=C2=A0=C2=A0 Wrapper for perl confi= guration perl5-5.32.1_3=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Practical Extraction and Report Lang= uage I have many p5- modules too installed but maybe I don't have the right=20 ones to run the script?
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?b4ac4aea-a051-fbfe-f860-cd7836e5a1bb>