The humble cp command

I am a great fan of the humble cp command in Unix. Some brief tips and tricks follow.

On many (most? all?) Unix systems like Linux when you type ‘cp’ you are actually invoking the alias

alias cp='cp -i'

that means no matter what you do, the command always runs in interactive mode. This is usually a good thing, a desirable thing. Except when you’re restoring your system from an old hard drive.

In that case you’ll be using this a lot

/bin/cp -r -f  [destination directory]

Like this:

/bin/cp -r -f /media/_home/myuser /home/myuser

Note that in order to capture hidden (“dot files”) as well as non-hidden files you don’t want to include a wildcard (“*”) character in your command string (you’d need to do a “/*.” for the visible, and then a “/.*”, for the invisible ones).

I used this in migrating to a new Scientific Linux 6.1 machine from an older CentOS 5.7 system. In the end I actually wound up having to be more surgical in what I copied, particularly when it came to dot (.) files. The main problem was with the Gnome desktop. Enough differences existed in its configuration on the source and target systems that it was easier to just rebuild the few customizations I really needed (like custom application launcher icons).