How to move or copy files listed by 'find' command in unix? How to move or copy files listed by 'find' command in unix? unix unix

How to move or copy files listed by 'find' command in unix?


Adding to Eric Jablow's answer, here is a possible solution (it worked for me - linux mint 14 /nadia)

find /path/to/search/ -type f -name "glob-to-find-files" | xargs cp -t /target/path/

You can refer to "How can I use xargs to copy files that have spaces and quotes in their names?" as well.


Actually, you can process the find command output in a copy command in two ways:

  1. If the find command's output doesn't contain any space, i.e if the filename doesn't contain a space in it, then you can use:

    Syntax:    find <Path> <Conditions> | xargs cp -t <copy file path>Example:    find -mtime -1 -type f | xargs cp -t inner/
  2. But our production data files might contain spaces, so most of time this command is effective:

    Syntax:   find <path> <condition> -exec cp '{}' <copy path> \;Example    find -mtime -1 -type f -exec cp '{}' inner/ \;

In the second example, the last part, the semi-colon is also considered as part of the find command, and should be escaped before pressing Enter. Otherwise you will get an error something like:

find: missing argument to `-exec'


find /PATH/TO/YOUR/FILES -name NAME.EXT -exec cp -rfp {} /DST_DIR \;