This is very closely a dupe of How do I include a pipe |
in my linux find -exec command?, but does not cover the case you are dealing with.
To get the filename, you can run a -exec sh -c
loop
find path/to/images -name "*.png" -exec sh -c '
for file; do
base64 "$file" | tr -d "\n" > "${file}.base64.txt"
done' _ {} +
Using find -exec
with +
puts all the search results from find
in one shot to the little script inside sh -c '..'
. The _
means invoke an explicit shell to run the script defined inside '..'
with the filename list collected as arguments.
An alternate version using xargs
which is equally expensive as the above loop would be to do below. But this version separates filenames with NUL
character -print0
and xargs
reads it back delimiting on the same character, both GNU specific flags
find path/to/images -name "*.png" -print0 |
xargs -0 -I {} sh -c 'base64 {} | tr -d "\n" > {}.base64.txt'