+3 votes
in Operating Systems by (12.4k 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 (14.2k 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)


$ 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)