11.5 C
New York
Monday, March 23, 2026

macos – The right way to discover solely folders that container particular kind of merchandise


There are most likely a number of methods to do that within the Terminal.  Right here’s one, which calls discover to seek for the photographs*, then dirname on every filename to extract the total listing identify, and eventually uniq to take away duplicates.

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

(Clearly, exchange pathToLookUnder with the trail to the folder you wish to search in.  Or cd to it first, and use . as a substitute.)

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 comprises a quote or related, xargs would usually attempt to break 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 possibly can in fact append | kind in order for you them ordered.

The outcomes are listed on the terminal.  You possibly can as a substitute 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 methods to establish the photographs.  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

Stay Connected

0FansLike
0FollowersFollow
0SubscribersSubscribe
- Advertisement -spot_img

Latest Articles