0

I can do the following to copy a file from subdirectories.

find . -name "file1.txt" -type f -exec cp {} ./distfolder \;

How do I change this code to copy multiple files (file1.txt, file5.txt, file6.txt) by their names from subdirectories?

Simply doing find . -name "file1.txt, file5.txt, file6.txt" -type f -exec cp {} ./distfolder \; doesn't work.

1 Answer 1

2

The -name test accepts a POSIX filename generation pattern, so

find . -name "file[156].txt"

For more complex cases, tests may be chained with the logical conjunction -o

find . \( -name "file1.txt" -o -name "file5.txt" -o -name "file6.txt" \)

See also this recent question How do you match zero or one character in the "-name" option of the "find" command?

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .