In Linux Copy File and Overwrite Only If Target Is Older [Duplicate]

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.

0
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.

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest