You can use find
to find a list of different file names, and then pipe it via xargs
to cp
:
find ./looking -type f \( -name "*.mp4" -or -name "*.jpg" \) | xargs cp -t ./found
This will copy files from the folder ./looking
to the folder /found
...
edit
Or in your case you probably just want to replace ./looking
with ./
updated version for macOS
Since macOS cp does not support -t
.
find . -type f ( -iname "*.log" -or -iname "*.jpg" ) | sed 's/ /\\ /g' | xargs -I '{}' cp '{}' ../test-out
Where:
- The
find
part looks for all files (not folders) named *.log or *.jpg, and not case sensative (-iname instead of -name)
- The
sed
part inserts a "\" before any white spaces in a path
- The
xargs
part uses placeholder ({}
) to put all the arguments into the cp
command.