Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

H2SO4

macrumors 603
Original poster
Nov 4, 2008
5,953
7,563
Hi all, hope well. Wondering if any can assist?

I have over the years collected many items and want to be able to list by containing folder.

Imagine I have taken pictures from many customers and organised them in this fashion;
Facilities company > End user company > End user site > SerialA > Picture1 from SerialA.
Facilities company > End user company > End user site > SerialB > Picture1 from SerialB.

The object of the search just so that I can see how many serials, (or folders), this is spread over so that I can mange them in other ways.

If I search for images, it will return all the images, (approx. 50,000).
If I search for folders it will return every folder that contains images but I don't really want that either.

What I want is a list where each returned result is a folder that contains ONLY image(s), and NOT a folder that contains a folder that contains an image. So that searching the 'Facilities company' folder would yield the following result;
SerialA
SerialB

Any search gurus out there know how to do?

I don't mind a little bit of Terminal or spending for a GUI search utility at all, and have already tried;
HoudahSpot, (otherwise brilliant but won't do what I need).
Pro Find
Easy Find
Find any file.
Alfred.

TIA.
 
Is the name that you have assigned, for the folder inside "end user site" folder, unique for each end user site? (and NOT only SerialA or SerialB ?
You may want to expand on what your process has been, when deciding how to name those "picture-level" folders
 
what kind of images/image format? would you like to list only folders which exclusively contain e.g., JPEGs - that is no other files - or are you referring foto subfolders containing at least one JPEG?
 
Hi again all. Thanks for your input thus far.
Thought I'd better explain with a picture, should make things clear.
Screenshot 2025-08-29 at 16.15.05.jpg

The idea is to end up with a list of serial numbers which of course would be a list of every unique item that I have pics for. The only things I want to appear in the list are the highlighted ones.
I can do the search more than once with jpeg, jpg, tiff, heic, png and bmp and then combine.
 
  • Like
Reactions: Brian33
In your example just above, SerialB occurs within both "End user site aa" and "End user sitebb".

How do you want this handled:
(1) "SerialB" occurs once in the output list,
or
(2) "SerialB" occurs multiple times in the output list (once for each End User Site it occurs in)


I'm no Unix wizard, so there's probably a more elegant way to do this, but I think I have a Terminal command which will do what you want. No files or directories are deleted or changed. Optionally you can create an output file. I tested this using the 'bash' command-line shell, but it seems to work fine in 'zsh' (which is now the default) also.

If you want identically-named Serial folders to appear in the output only once:

find -E "Documents/Facilities company" -iregex ".*\.jpg|.*\.png|.*\.jpeg|.*\.tiff|.*\.heic|.*\.bmp" | awk -F/ '{print $(NF-1)}' | sort | uniq

If you want identically-named Serial folders to appear in the output more than once, the best I can come up with at the moment is to include the end user site name (its parent folder name) in the output:

find -E "Documents/Facilities company" -iregex ".*\.jpg|.*\.png|.*\.jpeg|.*\.tiff|.*\.heic|.*\.bmp" | awk -F/ '{print $(NF-2)"/"$(NF-1)}' | sort | uniq

These commands will work with .jpg, .png, .jpeg, .tiff, .heic, .bmp files as images. Uppercase versions are also OK. Exact punctuation is important, of course; use copy & paste. If you want the output lines in a file, append
> outfile.txt (for example) to the command.


Explanation: There are four commands, with the output of each piped into the next. This 'find' command just lists all the image files found. Other extensions could be added.
find -E "Documents/Facilities company" -iregex ".*\.jpg|.*\.png|.*\.jpeg|.*\.tiff|.*\.heic|.*\.bmp"

That list is piped into 'awk' which separates the lines into fields separated by '/' and prints the second-to-last field of each line:
awk -F/ '{print $(NF-1)}'

There is still one output line for each image file. To get rid of duplicates, 'sort' the file and use 'uniq' to remove adjacent identical lines:
sort | uniq

Hope this helps! It was a fun little challenge for me.
 
Last edited:
you can use sort -u combining the sort | unique part. And instead of -iregex use -name which is faster when matching patterns.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.