I'm looking for an easy way to find and delete all files in a directory and all its subdirectories that do NOT contain certain strings in their name.
I tried starting with the find command first:
find . -type f \! \( -name "TMP_TGL_2" -o -name "PRES_SFC_0" \)
But it doesn't seem to exclude the second string pattern. How can I accomplish this?
Try this:
The wildcards round the patterns will insure that they match files which contain those strings (otherwise they would only match files with names that are identical to the strings).