Does cp -a refresh existing files, overwrite or skip

6,997

Solution 1

cp will overwrite all files.

what you are looking for if you do not want that behavior is the rsync command.

the -a option just means it will preserve the source file metadata, like creation time, owner, access mode and such..

Solution 2

Existing files will be over-written, as somewhat implied in gilles' answer to Difference between cp -r and cp -a.

Share:
6,997

Related videos on Youtube

Fat Monk
Author by

Fat Monk

Pooters: Been developing for web since 1993 (HTML, PHP, JavaScript etc). Also dabble in Free pascal and previously C++ via C++ Builder. Running Windows and Linux. A bit of Android dev in Java with a couple of apps in the Play Store. Other: Private Pilot, sliding on snow, video editing and graphics. Creations - Web: BlueBadgeParking.com, CumbrianDictionary.co.uk, GonMad.co.uk, NoOriginalThought.com Creations - App: AmALfi - Amazon Affiliate Link Creator, YABS - Yet Another Bill Splitter, Blue Badge Parking

Updated on September 18, 2022

Comments

  • Fat Monk
    Fat Monk almost 2 years

    If I use cp in archive mode e.g

    cp -a /my_old_directory/* /new_location/my_new_directory/
    

    to replicate a directory structure and all that is in it.

    If I then run the same command again will any changed files be refreshed or over-written or skipped?

    (I know rsync is more advanced at this kind of thing, I'm just curious about cp -a as I can't find any description of what it actually does in this case.