Bash – How to use a pipe in the exec parameter for a find command

bashfindshell

I'm trying to construct a find command to process a bunch of files in a directory using two different executables. Unfortunately, -exec on find doesn't allow to use pipe or even \| because the shell interprets that character first.

Here is specifically what I'm trying to do (which doesn't work because pipe ends the find command):

find /path/to/jpgs -type f -exec jhead -v {} | grep 123 \; -print

Best Answer

Try this

find /path/to/jpgs -type f -exec sh -c 'jhead -v {} | grep 123' \; -print

Alternatively you could try to embed your exec statement inside a sh script and then do:

find -exec some_script {} \;