2

Trying to pipe list of images from find to identify and I get no output.

Using this command, I get no results.

find . -iname "*.jpg" -type f | identify -format '%w:%h:%i' 

However, if I use this command, which doesn't use a pipe but instead uses find's -exec option it works normally.

find . -iname "*.jpg" -type f -exec identify -format '%w:%h:%i\n' '{}' \;

Does anyone know why this is happening and how to use pipe properly instead of find -exec?

ragouel
  • 179
  • 4
  • 15
  • `find -iname '*.jpg' -type f -exec identify -format '%w:%h:%i\n' {} +`. This will run `identify` on large batches of files instead of fork+exec for each of them. Or use `find ... -print0 | xargs -0 identify ...`. –  Aug 10 '19 at 16:09

3 Answers3

2

Figured it out, I needed to use xargs

find . -iname "*.jpg" -type f | xargs -I '{}' identify -format '%w:%h:%i\n' {}

the brackets '{}' are used to represent the file array.

ragouel
  • 179
  • 4
  • 15
2

This works for me:

identify -format '%w:%h:%i\n' $(find . -iname "*.jpg")


Note: I have added \n so that each image will list on a new line.

fmw42
  • 46,825
  • 10
  • 62
  • 80
1

Your first command, namely this:

find . -iname "*.jpg" -type f | identify -format '%w:%h:%i'

doesn't work because identify expects the filenames as parameters, not on its stdin.


If you want to make identify read filenames from a file, you would use:

identify -format '%w:%h:%i\n' @filenames.txt

If you want to make identify read filenames from stdin, (this is your use case) use:

find . -iname "*.jpg" -type f | identify -format '%w:%h:%i\n' @-

If you want to get lots of files done fast and in parallel, use GNU Parallel:

find . -iname "*.jpg" -print0 | parallel -0 magick identify -format '%w:%h:%i\n' {}
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • 1
    Mark, Good point about @-. Note: some systems may need their policy.xml ImageMagick file edited to permit use of that. – fmw42 Aug 10 '19 at 19:12