In Linux copy file and overwrite only if target is older

7,326
cp -u

According to the cp man page, -u will only overwrite file if the destination is older than the source.

It appears the -u option is not available for scp, so if you need to do it on a remote host, use rsync. By default, rsync skips files that have the same size, name, and last modified time. Rsync also has a -u option to skip destination files that are newer.

Share:
7,326

Related videos on Youtube

vladon
Author by

vladon

Updated on September 18, 2022

Comments

  • vladon
    vladon almost 2 years

    How in Linux using cp one can copy file to destination, but if destination exists, then overwrite only if destination is older than source?

    cp -f always overwrites, but overwrite is needed only if target is older than source.