Beginners Guide: Overwrite All Files With ‘cp’ Command In Linux

“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.

Comments

  1. Adam Dave says:

    To know the use and the implementation of the cp command that you can also get that from the help of the Apple Tech Support to generate the settings required for that.

Give me your feedback

This site uses Akismet to reduce spam. Learn how your comment data is processed.