0

I have a hard disk with a lot of folders and sub folders. The format is like that :

/ genre1 / artist / set of pictures1 / list of .jpg

but it can also be

/ genre2 / set of pictures2 / list of .jpg

I would like to get the full list of paths where the .jpg are. They are the last folder of each folder tree.

How can i do it with a shell script ? I was trying to use "find" with mindepth or maxdepth and -type d but i can't tell how many depth levels i must look for .. it can change.

Thanks

Fredv
  • 552
  • 1
  • 8
  • 22

1 Answers1

0

You can use the -links test as in this answer

find / -type d -links 2 -exec \
  find {} -maxdepth 1 -type f -name '*.jpg' -printf "%h\n" -quit \
\;

If you're not using gnu find, you can do something like

find / -type d -links 2 -exec \
  bash -c 'shopt -s dotglob nullglob; a=(*.jpg); ((${#a[@]}>0)) && echo "$1"' bash {} \
\;
Community
  • 1
  • 1
Reinstate Monica Please
  • 11,123
  • 3
  • 27
  • 48