Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force cp to overwrite without confirmation

I'm trying to use the cp command and force an overwrite.

I have tried cp -rf /foo/* /bar, but I am still prompted to confirm each overwrite.

like image 819
Thiyagarajan Varadharaj Avatar asked Dec 13 '11 11:12

Thiyagarajan Varadharaj


People also ask

How do you force overwrite on cp?

To view output when files are copied, use the -v (verbose) option. By default, cp will overwrite files without asking. If the destination file name already exists, its data is destroyed. If you want to be prompted for confirmation before files are overwritten, use the -i (interactive) option.

Does cp overwrite directory?

cp Without Overwriting the target Directory. We understand that if the target is an existing directory, we cannot use the simple command cp -r src target to solve this problem. However, cp provides a nice -T option to treat the destination as a normal file instead of a directory.

Does mv command overwrite files?

Attention: The mv command can overwrite many existing files unless you specify the -i flag. The -i flag prompts you to confirm before it overwrites a file. If both the -f and -i flags are specified in combination, the last flag specified takes precedence.


1 Answers

You can do yes | cp -rf xxx yyy, but my gutfeeling says that if you do it as root - your .bashrc or .profile has an alias of cp to cp -i, most modern systems (primarily RH-derivatives) do that to root profiles.

You can check existing aliases by running alias at the command prompt, or which cp to check aliases only for cp.

If you do have an alias defined, running unalias cp will abolish that for the current session, otherwise you can just remove it from your shell profile.

You can temporarily bypass an alias and use the non-aliased version of a command by prefixing it with \, e.g. \cp whatever

like image 66
favoretti Avatar answered Sep 29 '22 01:09

favoretti