Today I ran into a strange problem:
On centos cp command is “-interactive” by default:
cp -i, –interactive - prompt before overwrite
I had to copy a large folder with lots of subfolders onto another folder, overwriting all duplicate content.
Normaly you do that with:
$ cp -rf folder1/* folder2/
forcing with -f to overwrite, and making it recursive with -r
The problem was that on centos cp is -interactive by default, I had to press y -> enter a thousand times, which is not very pleasent.
The solution? the yes command! yes, it’s true, there is a yes command, beautiful.
Usage: yes [STRING]... or: yes OPTION Repeatedly output a line with all specified STRING(s), or `y'. --help display this help and exit --version output version information and exit
All you need to do is prepend command yes “yes” to your script or command. Ofcourse is usefull for recursive deleting files or other actions you may need
$ yes “yes” | your_command
$ yes “yes” | script
In my case, the solution was:
$ yes “yes” | cp -rf folder1/* folder2/
And it worked like a charm.