Find Files and Execute Command with Each
You need to
- Find files and
- Execute a command with each found file
This is how it works:
find . -name '*.jpg' -exec cp '{}' ../_output'{}' \;
The command finds all *.jpg
s via find . -name '*.jpg'
. Next with -exec cp
it is told to execute the command cp
for every file found. The {}
is the placeholder for the filename that find returns. Play around with each part of the command to see the output. Maybe for learning start with find . -name '*.jpg' -exec echo "file1: {}" \;
. You will also find out how important the \;
at the end is!