Many a times it happens you are trying to copy or move a large number of directories or files from oney" every time but it can be adjusted by the number of file is 2-3 but what if the number of files you are trying to copy is more than 100 then you cannot press "y" every time to overwrite location to another location and every time you get a prompt of "overwrite" as already a file with the new file name exists. It becomes really very hectic to press "
# cp -r /etc/ Folder/ cp: overwrite `Folder/etc/rc5.d'? y cp: overwrite `Folder/etc/ggz.modules.d/kdegames'? y cp: overwrite `Folder/etc/idmapd.conf'? y cp: overwrite `Folder/etc/bonobo-activation/bonobo-activation-config.xml'? y cp: overwrite `Folder/etc/csh.cshrc'? y cp: overwrite `Folder/etc/group-'?
So you see every time I have to press y to accept.
# cp -rvf /etc/ Folder/ cp: overwrite `Folder/etc/rc5.d'? y removed `Folder/etc/rc5.d' `/etc/rc5.d' -> `Folder/etc/rc5.d' cp: overwrite `Folder/etc/ggz.modules.d/kdegames'? y `/etc/ggz.modules.d/kdegames' -> `Folder/etc/ggz.modules.d/kdegames' cp: overwrite `Folder/etc/idmapd.conf'? y `/etc/idmapd.conf' -> `Folder/etc/idmapd.conf' `/etc/bonobo-activation-config.xml' -> `Folder/etc/bonobo-activation- config.xml' cp: overwrite `Folder/etc/csh.cshrc'? y
Now as you see above it is still prompting me for overwrite
# alias alias cp='cp -i' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias mv='mv -i' alias rm='rm -i' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
Now as you can see there is an alias entry for cp command as 'cp -i' and if you look out for
# cp --help -i, --interactive prompt before overwrite (overrides a previous -n option)
So as you can see and understand why it was asking for overwrite each time. So the only thing you need to do is unalias the entry
# unalias cp
Now let us try to copy
# cp -rvf /etc /Folder `/etc/sfcb/file.pem' -> `Folder/etc/sfcb/file.pem' `/etc/sfcb/sfcb.cfg' -> `Folder/etc/sfcb/sfcb.cfg' `/etc/sfcb/server.pem' -> `Folder/etc/sfcb/server.pem' `/etc/sfcb/client.pem' -> `Folder/etc/sfcb/client.pem' `/etc/mke2fs.conf' -> `Folder/etc/mke2fs.conf' `/etc/sysctl.conf' -> `Folder/etc/sysctl.conf'
So the files are getting copied without any prompt.
# vi .bashrc # .bashrc # User specific aliases and functions alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi
Remove the entry for cp command and save the file. This will permanently remove the alias entry for cp.
4 thoughts on “Forcefully overwriting while copying files”
I was searching from a long time looking for a solution to this. It really becomes head ache at times when copying no. of files.
You tips worked like a charm.
You can also run cp, and that will unalias the existing cp alias and won't prompt.
Thanks for the info..that was new to me as well.
will also work