Make `cp` choose no when prompted to overwrite
5,888
Solution 1
Try the cp -n
'noclobber' option.
It doesn't overwrite existing files and overrides a previous -i
option.
Solution 2
The -n option should not overwrite an existing file.
Author by
Kirk
Updated on September 18, 2022Comments
-
Kirk over 1 year
I have a list of files that I am copying around for various purposes. What my current command looks similar to this:
cat list_of_files | xargs -I {} /bin/cp -f {} /destination/dir
I am using the full path to
cp
so that the default alias ofcp -i
does not take effect. However, when I find a duplicate file, it is overwriting any that have already been copied. What I would like to do is to forcecp
to not overwrite and not prompt.Is there any way to do this?
-
Kirk almost 13 yearsyou know, I read that man page 3 times, and it got past me every time. Thanks.
-
Praesagus almost 9 yearsand yet it does if you don't use other options like -d.