From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Jean Louis <bugs@gnu.support>
Newsgroups: gmane.emacs.help
Subject: Re: Deleting files
Date: Mon, 22 Feb 2021 08:19:32 +0300
Message-ID: <YDM+5AjmO5Qay53i@protected.rcdrun.com>
References: <trinity-bfa3da62-97c1-43c4-9c64-f425065056af-1613948505572@3c-app-mailcom-bs09>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="9183"; mail-complaints-to="usenet@ciao.gmane.io"
User-Agent: Mutt/2.0 (3d08634) (2020-11-07)
Cc: Help Gnu Emacs <help-gnu-emacs@gnu.org>
To: michael-franzese@gmx.com
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 22 06:20:12 2021
Return-path: <help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org>
Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org
Original-Received: from lists.gnu.org ([209.51.188.17])
	by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
	(Exim 4.92)
	(envelope-from <help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org>)
	id 1lE3dk-0002IW-K1
	for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 22 Feb 2021 06:20:12 +0100
Original-Received: from localhost ([::1]:46158 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org>)
	id 1lE3dj-0003ha-Fo
	for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 22 Feb 2021 00:20:11 -0500
Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39804)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <bugs@gnu.support>) id 1lE3dO-0003hS-3V
 for help-gnu-emacs@gnu.org; Mon, 22 Feb 2021 00:19:50 -0500
Original-Received: from stw1.rcdrun.com ([217.170.207.13]:48021)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <bugs@gnu.support>) id 1lE3dM-0004O3-5L
 for help-gnu-emacs@gnu.org; Mon, 22 Feb 2021 00:19:49 -0500
Original-Received: from localhost ([::ffff:41.210.155.149])
 (AUTH: PLAIN securesender, TLS: TLS1.2,256bits,ECDHE_RSA_AES_256_GCM_SHA384)
 by stw1.rcdrun.com with ESMTPSA
 id 000000000001E1B8.0000000060333EF1.00000DAF; Sun, 21 Feb 2021 22:19:44 -0700
Mail-Followup-To: michael-franzese@gmx.com,
 Help Gnu Emacs <help-gnu-emacs@gnu.org>
Content-Disposition: inline
In-Reply-To: <trinity-bfa3da62-97c1-43c4-9c64-f425065056af-1613948505572@3c-app-mailcom-bs09>
Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support;
 helo=stw1.rcdrun.com
X-Spam_score_int: -18
X-Spam_score: -1.9
X-Spam_bar: -
X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: Users list for the GNU Emacs text editor <help-gnu-emacs.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/help-gnu-emacs>,
 <mailto:help-gnu-emacs-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/help-gnu-emacs>
List-Post: <mailto:help-gnu-emacs@gnu.org>
List-Help: <mailto:help-gnu-emacs-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/help-gnu-emacs>,
 <mailto:help-gnu-emacs-request@gnu.org?subject=subscribe>
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org
Original-Sender: "help-gnu-emacs"
 <help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org>
Xref: news.gmane.io gmane.emacs.help:128192
Archived-At: <http://permalink.gmane.org/gmane.emacs.help/128192>

* michael-franzese@gmx.com <michael-franzese@gmx.com> [2021-02-22 02:02]:
> I have two directories with files, one is the "source", the other
> "destination".  I would like to have a script that checks file
> in "source".  If file name and size matches that at "destination",
> the file at "source" is deleted.  Preferably using bash.

By using Emacs
==============

In Emacs that is already solved by using the function as below:

M-x dired-compare-directories

Process would be as following:

0. I advise to set the variable `dired-dwim-target' to TRUE, as "dwim"
   means "Do What I Mean". This variable will help Dired file
   operations to automatically offer the other window's directory.

1. Open two (or more) Emacs windows, one directory in one window,
   other directory in other window.

2. M-x dired-compare-directories

3. It will ask you for Lisp expression, you may then say something
   like: (not (= size1 size2)) in the prompt. That will compare
   directories by sizes. Those files with different sizes will be
   marked in both windows, you will chose from which window and
   directory to transfer files to other window.

4. Use `C' in Dired to copy or `R' to rename files to other window and
   directory.

It is possible to make it a script with Emacs, as Emacs may run in
batch mode. You would need to first change to specific directory by
using the `source' argument, and then supply `DIR2' variable by using
the `target' argument of a script, and I just guess without checking
that predicate would be the Lisp function as explained.

(dired-compare-directories DIR2 PREDICATE)

More about that may be found in the manual by evaluating this Lisp
expression:

(info "(emacs) Misc Dired Features")

By using Midnight Commander
===========================

Without Emacs, I know that this function exists in software Midnight
Commander, the command being `mc' and key binding C-x d, so by
invoking the function in Midnight Commander you also get it.

Such function depends on probability that the outcome will be as
wanted.

As what if file contains a phone number, but newer file contains newer
and current phone number. That makes both files of the same size and
older file would not get overwritten by the new file. Files may be
changed and still retain the same file size. Probability is law but is
still there. Data may be loss when relying on such function.

For Bash
========

Thus when using the Bash script, I would make sure that each file is
checked for its hash before deciding if to move it and later delete
it.

By using Rsync
==============

Rsync command offers the same functionality automatically. Thus
something like this:

$ rsync --remove-source-files -av /source/directory/ /target/directory/

would make sure that source files are deleted after synchronizing
those files from source directory.

In my opinion rsync would be most appropriate for you and I suggest
that you review its options and manual.

Jean