From nobody Fri May 5 07:01:14 2023 X-Original-To: freebsd-questions@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QCM6d56RDz49tQ0 for ; Fri, 5 May 2023 07:01:29 +0000 (UTC) (envelope-from pprocacci@gmail.com) Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QCM6d0T3rz4FHk for ; Fri, 5 May 2023 07:01:29 +0000 (UTC) (envelope-from pprocacci@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-38ded2d8bcaso794319b6e.0 for ; Fri, 05 May 2023 00:01:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683270087; x=1685862087; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=eMCY91cBRsoE8uAVQtRt2tjmorpRNcGvvm06BafHyzY=; b=R03mtHZh90pwoaE89FFDcw3WYbwuXqlMUtoF0QD0aR3L+cfPdyxEEXRYQkkjcGH/Q5 rtaOR38sxw1FB6G35pJjtqTWWvn8L5lMhGx4uCw94YSJw8ixVB25C2WJ1U0E+53aLQgB RPdF7kKcRpussXJVVrLf2FKPPgtJJ0Tz1zrJ7t+BkpemwS2BiBtk2gk9D02PJCIpdeNj SuciBHPZrC+ujqNfbHj8rxDg0HZDWmNMXKHRk9ZxOzsfm3FP+WirPnj23vv0tuuj/qWq 12bMoVOeKK7hb3IC6tHD6vHFMW3S667TUXpTZv9Idgu5mThSyDVB3X/EN0z5fFViCVDd tS7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683270087; x=1685862087; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eMCY91cBRsoE8uAVQtRt2tjmorpRNcGvvm06BafHyzY=; b=VOUDX9fzDnl08Zg/YNxEiIIbK+4P8ShGy2q+oH/GcwkKbjjmBBiRd1eOosdbc07pM9 2BkkL5pJ+vlC0nH5MDuznuUmAn72f1DbYUN2MFsq2B/BM8b6xYlsFwuqNbSIRGHHQZOZ v2EsAHH2SMKBvyUbZYsXctlQQPz2xeRKu6JjY1tbrdmyvLRAcZ+OXF6SSDP8DY5dcusk nu1HAnFKPwPzd5rkXMrT6hBr9xAAKeMdx66MBkpO5WEEtuAxAZA0jl0CASvlsAz8u2J5 Jd8luL0r0hJXtVeae8+X7eHcIQ/ZZteFMgzKQjlSj3ZDPjKXpXOd8fl4ldxraAu2iPaS WHgA== X-Gm-Message-State: AC+VfDw6yVWz3afZqzPPlxKaL82IYKoB9AXii7jaz8sYz2qI34cu1WL4 GzGONP8WlBwUc81Kdh1hf+ZKQg3i7WnOKjzW8Sw3+hipBW+d X-Google-Smtp-Source: ACHHUZ57vk9SnG+KR5STtByaKn8Em4tEHFAd5ZURn40IVBP24+V4tPyuT/5jfk09HzVQnsRN+I/M5MYfogrVZG8h0/M= X-Received: by 2002:a05:6808:2989:b0:38d:f298:6cfc with SMTP id ex9-20020a056808298900b0038df2986cfcmr196375oib.0.1683270087143; Fri, 05 May 2023 00:01:27 -0700 (PDT) List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 References: <9887a438-95e7-87cc-a162-4ad7a70d744f@optiplex-networks.com> <344b29c6-3d69-543d-678d-c2433dbf7152@optiplex-networks.com> <7747f587-f33e-f39c-ac97-fe4fe19e0b76@optiplex-networks.com> In-Reply-To: From: Paul Procacci Date: Fri, 5 May 2023 03:01:14 -0400 Message-ID: Subject: Re: Tool to compare directories and delete duplicate files from one directory To: Kaya Saman Cc: freebsd-questions@freebsd.org Content-Type: multipart/alternative; boundary="0000000000009af6d205faecdbf6" X-Rspamd-Queue-Id: 4QCM6d0T3rz4FHk X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N --0000000000009af6d205faecdbf6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, May 5, 2023 at 12:06=E2=80=AFAM Kaya Saman wrote: > > On 5/5/23 04:36, Paul Procacci wrote: > > #!/usr/bin/env perl > > > > use strict; > > use warnings; > > > > sub msgDie > > { > > my ($ret) =3D shift; > > my ($msg) =3D shift // "$0 dir_base dir\n"; > > print $msg; > > exit($ret); > > } > > > > msgDie(1) unless(scalar @ARGV eq 2); > > > > my $base =3D $ARGV[0]; > > my $dir =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) > > { > > next if($_ eq '.' || $_ eq '..'); > > next if(! -f "$base/$_"); > > > > my ($ref) =3D (stat("$base/$_"))[7]; > > my ($src) =3D (stat("$dir/$_"))[7]; > > unlink("$dir/$_") if($ref =3D=3D $src); > > } > > > To start with this is the directory structure: > > > ls -lhR /tmp/test1 > total 1 > drwxr-xr-x 2 root wheel 3B May 5 04:57 dupdir1 > drwxr-xr-x 2 root wheel 3B May 5 04:57 dupdir2 > > /tmp/test1/dupdir1: > total 1 > -rw-r--r-- 1 root wheel 8B Apr 30 03:17 dup > > /tmp/test1/dupdir2: > total 1 > -rw-r--r-- 1 root wheel 7B May 5 03:23 dup1 > > > ls -lhR /tmp/test2 > total 1 > drwxr-xr-x 2 root wheel 3B May 5 04:56 dupdir1 > drwxr-xr-x 2 root wheel 3B May 5 04:56 dupdir2 > > /tmp/test2/dupdir1: > total 1 > -rw-r--r-- 1 root wheel 4B Apr 30 02:53 dup > > /tmp/test2/dupdir2: > total 1 > -rw-r--r-- 1 root wheel 7B Apr 30 02:47 dup1 > > > So what I want to happen is the script to recurse from the top level > directories test1 and test2 then expected behavior should be to remove > 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 Wrapper for perl configuration > perl5-5.32.1_3 Practical Extraction and Report Language > > > I have many p5- modules too installed but maybe I don't have the right > ones to run the script? > > > - My script doesn't have any output. - My script doesn't recurse directories. - My script requires no modules. - You just need perl5 installed. So you want something like this: % find test* -type f -ls 131318 9 -rwxr-xr-x 1 pprocacci pprocacci 763 May 5 06:58 test.pl 132503 9 -rw-r--r-- 1 pprocacci pprocacci 5 May 5 06:52 test1/dupdir2/dup1 132898 9 -rw-r--r-- 1 pprocacci pprocacci 8 May 5 06:51 test1/dupdir1/dup 132771 9 -rw-r--r-- 1 pprocacci pprocacci 4 May 5 06:52 test2/dupdir1/dup 133006 9 -rw-r--r-- 1 pprocacci pprocacci 5 May 5 06:52 test2/dupdir2/dup1 And after the run of the perl script like so: % ./test.pl test1 test2 You want it to be like this: % find test* -type f -ls 131318 9 -rwxr-xr-x 1 pprocacci pprocacci 763 May 5 06:58 test.pl 132503 9 -rw-r--r-- 1 pprocacci pprocacci 5 May 5 06:52 test1/dupdir2/dup1 132898 9 -rw-r--r-- 1 pprocacci pprocacci 8 May 5 06:51 test1/dupdir1/dup 132771 9 -rw-r--r-- 1 pprocacci pprocacci 4 May 5 06:52 test2/dupdir1/dup If so: #################################################### #!/usr/bin/env perl use strict; use warnings; sub msgDie { my ($ret) =3D shift; my ($msg) =3D shift // "$0 dir_base dir\n"; print $msg; exit($ret); } sub doit { my($base, $cur) =3D @_; opendir(my $dh, $cur) or msgDie("Unable to open directory: $cur\n"); while(readdir $dh) { next if($_ eq '.' || $_ eq '..'); if(-d "$cur/$_"){ doit("$base/$_", "$cur/$_"); next; } next if(! -f "$base/$_"); my ($ref) =3D (stat("$base/$_"))[7]; my ($src) =3D (stat("$cur/$_"))[7]; unlink("$cur/$_") if($ref =3D=3D $src); } } msgDie(1) unless(scalar @ARGV eq 2); my $base =3D $ARGV[0]; my $dir =3D $ARGV[1]; msgDie(1, "base diretory doesn't exist\n") unless -d $base; msgDie(1, "source diretory doesn't exist\n") unless -d $dir; doit($base, $dir); #################################################### ~Paul --=20 __________________ :(){ :|:& };: --0000000000009af6d205faecdbf6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable



On Fri, May 5, 20= 23 at 12:06=E2=80=AFAM Kaya Saman <kayasaman@optiplex-networks.com> wrote:

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 $b= ase;
> 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=A0=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
directories test1 and test2 then expected behavior should be to remove
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 configu= ration
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 Langua= ge


I have many p5- modules too installed but maybe I don't have the right =
ones to run the script?




- My script doesn't have any output.
- My script doesn't recurse directories.
- My script requires no modules.
- You just need perl5 installed.

So you want = something like this:

% find test* -type f -ls
131318 =C2=A0 = =C2=A0 =C2=A0 =C2=A09 -rwxr-xr-x =C2=A0 =C2=A01 pprocacci =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pprocacci= =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 763 May =C2=A05 06:58
t= est.pl
132503 =C2=A0 =C2=A0 =C2=A0 =C2=A09 -rw-r--r-- =C2=A0 =C2=A01= pprocacci =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0pprocacci =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 5 May =C2=A05 0= 6:52 test1/dupdir2/dup1
132898 =C2=A0 =C2=A0 =C2=A0 =C2=A09 -rw-r--r-- = =C2=A0 =C2=A01 pprocacci =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pprocacci =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 8= May =C2=A05 06:51 test1/dupdir1/dup
132771 =C2=A0 =C2=A0 =C2=A0 =C2=A09= -rw-r--r-- =C2=A0 =C2=A01 pprocacci =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pprocacci =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 4 May =C2=A05 06:52 test2/dupdir1/dup
133006 =C2=A0 =C2=A0 = =C2=A0 =C2=A09 -rw-r--r-- =C2=A0 =C2=A01 pprocacci =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pprocacci =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 5 May =C2=A05 06:52 test2/dupdir2/dup1
And after the run of the perl script like so:
% ./test.pl test1 test2

You want it to be like this:

% = find test* -type f -ls
131318 =C2=A0 =C2=A0 =C2=A0 =C2=A09 -rwxr-xr-x = =C2=A0 =C2=A01 pprocacci =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pprocacci =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 763 May = =C2=A05 06:58 test.pl
132503 =C2=A0 =C2= =A0 =C2=A0 =C2=A09 -rw-r--r-- =C2=A0 =C2=A01 pprocacci =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pprocacci = =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 5 May =C2=A05 06:52 test1/dupdir2/dup1
1= 32898 =C2=A0 =C2=A0 =C2=A0 =C2=A09 -rw-r--r-- =C2=A0 =C2=A01 pprocacci =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0pprocacci =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 8 May =C2=A05 06:51 test1/dup= dir1/dup
132771 =C2=A0 =C2=A0 =C2=A0 =C2=A09 -rw-r--r-- =C2=A0 =C2=A01 p= procacci =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0pprocacci =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 4 May =C2=A05 06:5= 2 test2/dupdir1/dup

If so:

####################################################
#!/usr/bin/env perl

use strict;
use warnings;

sub msgD= ie
{
=C2=A0 my ($ret) =3D shift;
=C2=A0 my ($msg) =3D shift // &qu= ot;$0 dir_base dir\n";
=C2=A0 print $msg;
=C2=A0 exit($ret);
= }

sub doit
{
=C2=A0 my($base, $cur) =3D @_;

=C2=A0 open= dir(my $dh, $cur) or msgDie("Unable to open directory: $cur\n");<= br>=C2=A0 while(readdir $dh)
=C2=A0 {
=C2=A0 =C2=A0 next if($_ eq = 9;.' || $_ eq '..');
=C2=A0 =C2=A0 if(-d "$cur/$_"= ){ doit("$base/$_", "$cur/$_"); next; }
=C2=A0 =C2= =A0 next if(! -f "$base/$_");

=C2=A0 =C2=A0 my ($ref) =3D = (stat("$base/$_"))[7];
=C2=A0 =C2=A0 my ($src) =3D (stat("= ;$cur/$_"))[7];
=C2=A0 =C2=A0 unlink("$cur/$_") if($ref = =3D=3D $src);
=C2=A0 }
}

msgDie(1) unless(scalar @ARGV eq 2);<= br>
my $base =3D $ARGV[0];
my $dir =C2=A0=3D $ARGV[1];

msgDie(= 1, "base diretory doesn't exist\n") unless -d $base;
msgDi= e(1, "source diretory doesn't exist\n") unless -d $dir;
doit($base, $dir);
###################################################= #

~Paul

--
__________= ________

:(){ :|:& };:
--0000000000009af6d205faecdbf6--