Recursive copy of files overwriting existing files

Here is a trick I just learned, again. It is amazing the things you forget and come back to every so often.

 cp command, at least in CentOS, defaults with alias cp -i (interactive). To bypass this and run a copy overwriting existing file you need to use /bin/cp or unalias the cp command. I am unsure about this being the default in other linux distros.

/bin/cp -Rfu source /var/www/html/

or

unalias cp
cp -Rfu source /var/www/html/

-R: Recursively copy files from directory.
-f:  if an existing destination file cannot be opened, remove it and try again
-u: copy only when the SOURCE file is newer than the destination file or when the destination file is missing

Popular Posts