“cp” is one of the most frequent use command to copy files or directory in Linux environment. “cp” is short from “copy”. This linux simple command is to copy files or directories in one server environment. To copy files or directories to another remote host you can use “rsync” or “scp” instead.
But when you want to copy and overwrite a whole directories with many files in it, it will keep asking you if you want to overwrite it or not. Can you imagine when you copying 1000 files and you need to answer “yes” for 1000 times? So this is a little tricks to answer it “yes” for all the overwrite prompt.
yes | cp -R <source path> <target path>
The above script will answer all the overwrite prompt with “yes”, and overwrite the whole files and directories.
The other alternative you can use is with rsync command, it also overwrite your target folder.
Warning: make sure you are understand what you are doing since you cannot rollback the overwritten files.