How to avoid 'are the same file' warning message when using cp in Linux?

The problem is that you try to copy a file to itself. You can avoid it by excluding the destination directory from the results of the find command like this:

find "$HOME" -name '*.txt' -type f -not -path "$HOME/newdir/*" -print0 | xargs -0 cp -t "$HOME/newdir" 

try using install instead, this replaces by removing the file first.

install -v target/release/dynnsd-client target/
removed 'target/dynnsd-client'
'target/release/dynnsd-client' -> 'target/dynnsd-client'

and then remove the source files

Tags:

Linux

Bash

Copy

Cp