Saturday, June 18, 2011

Linux: Forcing cp to overwrite

As a precaution, I have the following three lines in my .bashrc file.

# SAFETY ALIASES
       
   alias rm="rm -i"
   alias mv="mv -i"
   alias cp="cp -i"


When I try to move or copy something onto a file that already exists it gives me a warning prompt. So far, so good.

Sometimes, I intentionally want to overwrite a bunch of files. With mv, I just say something to the effect of

mv -f dir1/*.dat .

to move all the *.dat files from dir1 into the current working directory. Unfortunately cp -f dir1/*.dat . does not work. A trick is to use the command "yes".

So yes | cp -f dir1/*.dat . seems to fix the problem.




No comments:

Post a Comment