Find 2nd level directories without files with a certain extension

I have a lot of directories and subdirectories like:

abc/123/

abc/456/

def/789/

Some of them have jpeg files on them:

abc/123/

abc/456/foo.jpg

abc/456/bar.jpg

def/789/foo.jpg

I want to find the one that are missing a jpg

Learning from here I was able to get what I wanted with:

find . -mindepth 2 -maxdepth 2 -type d ‘!’ -exec sh -c ‘ls -l “{}”|egrep -i -q “*\.jpg$”‘ ‘;’ -print

Advertisements

How to remove annoying tags from every srt subtitle file

Sites like opensubtitles.org have the annoying habit of tagging their files with subtitles like “Tip for download: Open Subtitles MKV Player” and “Downloaded from http://www.opensubtitles.org”.

Here is a fast single command to get rid of all that on all subrip (.srt) files, using find, sed, and a bit of regex:

find . -name \*.srt -execdir sed -i '/pen.*ubtitles/d' {} +

I did it for dozens of files in one command ;)

find” searches all subdirectories below the current one (.) for every file with the srt extension (-name \*.srt) and executes the sed command that deletes on those files ({} +) the lines matching the regex pattern (pen.*ubtitles).