Two commands in the AWS S3 CLI that can be confusing to differentiate are
sync. These commands have similar descriptions, and many developers use them interchangeably without understanding the differences.
This article will list the key differences between the two commands.
cpwill copy all files even if they already exist in the destination folder.
cpdoesn’t support the deletion of files in the destination folder, even if you deleted the files from the source folder.
Syncwill only copy new and updated files from the source directory to the destination. Sync will first look at the destination folder before copying files over.
--deleteflag supports the deletion of files in the destination folder but no longer in the source folder.
synccompares the size of the file and the last modified timestamp to check if a file needs updating. Sync doesn’t compare file contents.
When to use cp?
cpis a simpler and more performant operation than sync. Use it when you copy a few files and don’t care about keeping directories in sync.
When to use sync?
syncwhen you want to keep the structure of the source and destination folders in sync. E.g., maintaining a static website.
syncgenerally copies fewer data than cp since only new or updated files are eligible.