When copy with force doesn’t work in Linux bash…

Hidden feature alert! I guess I have been a good boy and use sudo more than I do log in as root, or I would have discovered this much earlier on. While updating some website software with a new version, I wanted to recursively copy files from a new tar ball into the old web site vhost location – while also forcing it to overwrite existing files.

Naturally, I used the cp command, but hit some interesting glitch…

Now that should suppress promptings for overwriting existing files right? Well, not always. Try logging in as root on Fedora (and others?) and you will still find that you are prompted to confirm each overwrite. (This wasn’t the case on RHEL by the way.) Is it a bug in bash, or are you really just not typing it right? Neither! It’s not a bug, it’s a feature! Apparently us Linux admins need a little safeguarding from time to time. I’m sure I opt’ed in somewhere. So the default behaviour of these commands was overridden by an alias setting in .bashrc (Mr. Power Admin, meet Nanny State… 😉 ). There the cp and mv commands are set to force the –interactive feature instead of blindly accepting a -rfwithout complaint. I won’t complain, but it was a waste of a few minutes. From .bashrc:

Comment out the line you detest the most and open a new terminal, and your back to nuking your system with ease. Whew… I’m pretty sure this behaviour is part of some certification quiz question somewhere, to weed us novices from the cream of the crop 🙂 Keep your crop – I just want the power.


© Tyler Mitchell / Spatialguru.com