Some Linux distributions configure
cp as an alias for cp -i. This makes the command ask before overwriting an existing file, even when you add -f.Check for an alias
bash_snippet
Bash · 2 lines|
| type cp |
| alias cp |
If the output includes
alias cp='cp -i', the shell expands the alias before running the command.Bypass the alias for one command
Prefix the command with a backslash to prevent alias expansion:
bash_snippet
Bash · 1 line|
| \cp -f install.log /path/to/destination/ |
For directories, add
-r:bash_snippet
Bash · 1 line|
| \cp -rf source_directory/ /path/to/destination/ |
-f can remove an existing destination file if it cannot otherwise be opened; it does not override permissions or guarantee every copy will succeed. Review the destination carefully: bypassing -i can overwrite files without confirmation.Remove the alias from the current shell
bash_snippet
Bash · 1 line|
| unalias cp |
This change lasts only for the current shell. To make it persistent, remove or comment out the alias in the shell startup file that defines it, such as
~/.bashrc. Open a new shell or reload the file afterward. Removing an alias from a file does not automatically remove an alias already active in the current shell.✦ 卷终 · 柯航存卷 ✦