CODE/2022-11-25

Copy Files Without Overwrite Prompts in Linux

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.
COMPANION ESSAYS / 思想脉络与互照篇目
同卷深读2026-05-22 ·

Installing Python 3 Alongside System Python on CentOS 7

同属「系统工程卷」脉络衍生思考与工程推演推演阅读 →
跨界互照2026-08-22 ·

我的书架:03|金融经管:经济运行、金融体系与企业治理

我的书架:03|金融经管:经济运行、金融体系与企业治理

跨领域对照思辨 · 从「思想随笔」视界互为印证推演阅读 →
RELATED INDEX / 相关阅读索引
柯航hang.ke·© 2014—2026
CC BY-NC 4.0·