โœ… How to Force cp to Overwrite Without Confirmation on AlmaLinux

In AlmaLinux (like other RHEL-based distributions), the cp command is typically aliased to run in interactive mode by default, which means it prompts before overwriting files. This guide shows how to bypass the confirmation and force overwrites.


๐Ÿ” Check if cp is Aliased (Common on AlmaLinux)

Run this command:

alias

You will likely see:

alias cp='cp -i'

This means every time you run cp, it runs as cp -i (interactive), asking for confirmation before overwriting.


โŒ Incorrect Method: Using yes Pipe

Trying:

yes | cp -r bin/ test/

Does not bypass the alias or confirmation.


โœ… Recommended Options

Option 1: Use a Backslash (\) to Bypass the Alias

\cp -r bin/ test/

The backslash tells the shell to use the actual binary (/bin/cp) instead of the aliased version.


Option 2: Temporarily Unalias cp for the Session

unalias cp
cp -r bin/ test/

This disables the cp -i alias only for your current session or script.


๐Ÿงน Optional: Remove the Alias Permanently

If you prefer not to have cp aliased at all, you can remove or comment it from your shell config:

Edit your shell profile (for example, if you’re using bash):

nano ~/.bashrc

Look for a line like:

alias cp='cp -i'

And comment it out:

# alias cp='cp -i'

Then reload your shell:

source ~/.bashrc

๐Ÿงพ Summary Table (AlmaLinux)

ActionCommand
Check aliasalias
Force overwrite with backslash\cp -r source/ dest/
Unalias temporarilyunalias cp
Remove alias permanentlyEdit ~/.bashrc and remove alias
Helpman cp
Scroll to Top