Use:
find . -type f -exec sh -c 'echo "$(identify -format %w-%h "$1")"' sh {} \;
Explanation
The problem is with the way bash expands variables
find * -type f -exec echo "$(identify -format '%w-%h' {})" \;
First bash expands what is in side $(...)
:
find * -type f -exec echo 'identify: unable to open image `{}': No such file or directory...' \;
At which point find will use the same exec statement for all commands with a rather useless argument. What you want to do is suppress the bash expansion for inside the finds exec. You can stop bash expanding things by placing them inside single quotes
find * -type f -exec echo '$(identify -format %w-%h {})' \;
But here we lose expansion completely, we can inject it back by running the expression with sh -c
find * -type f -exec sh -c 'echo "$(identify -format %w-%h {})"' \;
Having {}
within the shell script can also lead to some unexpected errors when dealing with whitespace or quotes or any character special to the shell in file names. To get around this you should move the {}
as an argument to sh with:
find * -type f -exec sh -c 'echo "$(identify -format %w-%h "$1")"' sh {} \;
See this question/answer for a more detailed explanation of this.
Finally you can replace the *
with .
to let find
find the files in the current directory by itself (and include hidden ones and not fail for filenames starting with -
).
Additionally, you can add the -x
flag to sh
to get it to print out what was it executed to help with debugging the command - this can be very noisy for a lot of files.
echo
? – Kusalananda Sep 25 '17 at 20:48echo
, Im going to swap that out with amv
in order to rename the file. – Jeff Oct 11 '17 at 14:57