You can use cp -rf option to forcefully overwrite the destination file if already exists.
Example:
Create some files and directories:
1 2 3 |
mkdir -p mydir1 mydir/mydir1 ## create some files and directories echo "one" > mydir1/myfile1 echo "two" > mydir/mydir1/myfile1 |
Force cp command to overwrite without confirmation:
1 2 3 |
cat mydir/mydir1/myfile1 ## returns two cp -rf mydir1 mydir ## overwrites mydir1 and its content inside mydir with mydir1 and its content cat mydir/mydir1/myfile1 ## returns one |
if you still getting prompts that means somewhere an alias has been defined for cp with cp -i. In this case, directly execute the cp binary with -rf option
1 2 3 4 |
which cp ## returns /bin/cp /bin/cp -rf mydir1 mydir rm -rf my* |