Page 1 of 1

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!

macOS/Linux - Find ...
Clear all

[Solved] macOS/Linux - Find all directories that do not have a trailer

1 Posts
1 Users
0 Reactions
Famed Member Admin
Joined: 11 years ago
Posts: 2714
Topic starter  

I was asked to look and see if I could come up with a trick to "easily" find all directories in my friends video collection, that did not have a trailer file.

For reference:

Trailers are called "trailer.mp4" in this example, and the root path of all video directories is "/Volumes/SomeShare/Multimedia/Movies" - replace these with the proper info for your setup.

find /Volumes/SomeShare/Multimedia/Movies -maxdepth 1 -mindepth 1 -type d '!' -exec sh -c 'ls -1 "{}"|egrep -iq "trailer.mp4" ' ';' -print

This one liner will dig through all directories in "/Volumes/SomeShare/Multimedia/Movies".
It will however only go exactly one level deep (-maxdepth 1 -mindepth 1), meaning it will look into "/Volumes/SomeShare/Multimedia/Movies/A Movie/" but not in "/Volumes/SomeShare/Multimedia/Movies/A Movie/Pictures/".
Picking up those that do not have trailer.mp4 in it.

Just posting this here so my friend can copy it straight from here, and maybe its helpful for other that are looking for directories that do not contain a certain file. Eg. missing cover images in your music collection. If that requires 2 files, then you could do something like this:

find /Volumes/AllShares/Multimedia/Music -mindepth 1 -maxdepth 1 -type d '!' -exec sh -c 'ls -1 "{}"|egrep -i -q "cover\.(jpg|png)"' ';' -print