+3 votes
in Operating Systems by (7.9k points)
I want to copy all files from one folder to another but do not want to overwrite any existing file in the destination file. Any idea?

1 Answer

+2 votes
by (11k points)

Try cp -n option. It will copy but will not overwrite. The man page of cp says:

 -n, --no-clobber
              do not overwrite an existing file (overrides a previous -i option)

Example:

$ cp -n -R * destination_folder

-R is for recursive copy.

 -R, -r, --recursive
              copy directories recursively

If you want to do it interactively, you can use -i

 -i, --interactive
              prompt before overwrite (overrides a previous -n option)
 

...