24.1 C
New York
Wednesday, August 27, 2025

macos – Learn how to discover solely folders that container particular sort of merchandise


There are in all probability a number of methods to do that within the Terminal.  Right here’s one, which calls discover to seek for the pictures*, then dirname on every filename to extract the total listing identify, and at last uniq to take away duplicates.

discover 'pathToLookUnder' -iname '*.jpg' -print0 | xargs -0 dirname | uniq

(Clearly, exchange pathToLookUnder with the trail to the folder you need to search in.  Or cd to it first, and use . as an alternative.)

That is structured as a pipeline: the filenames that discover lists are handed on to dirname (utilizing xargs to name it for every one) and the outcomes then handed to uniq.

The ‘-print0’ and ‘-0’ flags work round issues with particular characters.  If any of the filenames accommodates a quote or related, xargs would usually attempt to cut up there.  To work round that, ‘-print0’ tells discover to separate filenames with a zero byte; and ‘-0’ tells xargs to separate solely on zero bytes.  So this could work for any filenames (that don’t include newlines).

It will return the folder names in an unspecified order.  You may after all append | type in order for you them ordered.

The outcomes are listed on the terminal.  You may as an alternative save them to a file, by appending >filename.txt.  Or you’ll be able to copy them to the clipboard by appending | pbcopy (to allow them to then be pasted into different apps).

(* You haven’t but specified learn how to determine the pictures.  For the sake of argument, this assumes all of them finish with .jpg.)

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles