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.

Share:
5,888
Kirk
Author by

Kirk

Updated on September 18, 2022

Comments

  • Kirk
    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 of cp -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 force cp to not overwrite and not prompt.

    Is there any way to do this?

  • Kirk
    Kirk almost 13 years
    you know, I read that man page 3 times, and it got past me every time. Thanks.
  • Praesagus
    Praesagus almost 9 years
    and yet it does if you don't use other options like -d.