What about an if-then statement in the script, like so:
for f in *.*;
        do


If exist /path to destination folder/$F [File in question] then
         diff $F /path to destination/$f and check which way the pipe points.
        if pipe points left (indicating destination file is newer, larger, etc 
than original file
bypass $F
Else cp $F to /path to destination/$F
:done

Now, the above looks strange, but it’s my methodology for writing actual bash 
scripts. Firstly, define the problem in plain English, then look up the 
appropriate commands and actions. It’s very basic, but it does allow me to 
codify my thought processes.

Do with it what you will.

-Eric
From the Central Offices of the Technomage Guild, Software maintenance 
infrastructure Dept.


On Jul 5, 2025, at 9:15 AM, Arun Khan via PLUG-discuss 
<plug-discuss@lists.phxlinux.org> wrote:



On Sat, Jul 5, 2025 at 8:53 AM Michael via PLUG-discuss 
<plug-discuss@lists.phxlinux.org <mailto:plug-discuss@lists.phxlinux.org>> 
wrote:
Simple question: How does one copy all files except those exiting already?
---------------------------------------------------

IMO, rsync is better for your objective. It does a file by file comparison and 
copies only that have changed or do not exist in the dest dir.

rsync -aP --log-file=/var/tmp/rsync-$$.log <origin dir> <dest dir>
--
Arun Khan
---------------------------------------------------
PLUG-discuss mailing list: PLUG-discuss@lists.phxlinux.org
To subscribe, unsubscribe, or to change your mail settings:
https://lists.phxlinux.org/mailman/listinfo/plug-discuss

---------------------------------------------------
PLUG-discuss mailing list: PLUG-discuss@lists.phxlinux.org
To subscribe, unsubscribe, or to change your mail settings:
https://lists.phxlinux.org/mailman/listinfo/plug-discuss

Reply via email to