others-how to copy from source to destination without overwrite in Linux

1. Purpose

In this post, I would demo how to copy files from source to destionation without overwrite target files(just copy new files) in Linux System.

2. Environment

  • Mac or Linux

3. The solution

You can use the below command to solve this problem:

$ rsync -a -v --ignore-existing src dest

For example, if you want to copy from source directory adir to destination directory bdir, you can do this:

$ rsync -a -v --ignore-existing adir bdir

What is rsync?

Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied. It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use.

What is --ignore-existing option in rsync?

--ignore-existing       skip updating files that exist on receiver

What is -a option in rsync?

The -a option is a combination flag. It stands for “archive” and syncs recursively and preserves symbolic links, special and device files, modification times, group, owner, and permissions. It is more commonly used than -r and is usually what you want to use.

At last, -v means verbose.

Now it works!

4. Summary

In this post, I demonstrated how to copy files without overwriting the files in target directory .