Copying files in Red Hat/CentOS without prompting, -f –force flag being ignored

Something annoying about Red Hat/CentOS/Fedora I had forgotten after years of Debian, Ubuntu and SuSE (or something that they’ve introduced recently, I’m not sure) is that cp is an alias to cp -i, as in it is interactive by default. Therefore the following will still prompt you for overwriting:

cp * -Rf /var/somewhere/new_location

To get around this just use the cp binary directly

/bin/cp * -Rf /var/somewhere/newlocation

1 comment

Leave a Reply to Bogdan Stoica Cancel reply

  • It’s because of the default alias. On Centos, there is an alias for cp in /root/.bashrc file (alias cp=”cp -i”) which instructs copy to ask for confirmation. You can use /bin/cp directly to skip that prompt or you can create a new alias like copy=/bin/cp or you can comment the alias in /root/.bashrc file.

    That option was added in order to prevent to accidentally overwrite an existing file by copying another file on it (it also applies to rm command and mv command).