How do I find folders without a certain name?

I'm trying to find a lot of folders, all without a certain bracket. They're movie folders, like so:

Zombie Flesh Eaters (1979) [tmdb-7219]
Zombieland (2009) [tmdb-19908]
Zombieland Double Tap (2019) [tmdb-338967]

But I need to find the ones WITHOUT the [tmdb] bracket.

I'm not sure how to do this?

Quick edit: Tried using the reg-ex \[.*?\] to find everything with a bracket in it, but I'm not sure if that works properly (I'm not that good at regex, but using a reg-ex tester confirms it looks for anything inside brackets).

But I need to find the folders WITHOUT the brackets.. And I don't know how to do this


Solution 1:

find features the -not operator. Tell it where to search, what kind of item to find (e.g. -type d to find only folders) and what should not be in the name, i.e -not -name '*\[*\]'. Thus

find /somewhere -type d -not -name '*\[*\]'

Solution 2:

This could be done easily.

ls -Aq1 | grep -Pv '.*\[tmdb-\d+\].*'

Piping after ls is considered a bad thing in general however, I assume all the folders aren't weirdly named because they're just movie folders, so I think piping after ls is fine here.

I haven't tested it but I'm pretty confident that it should work.

Also, I'm guessing that you'll be putting those folders in a loop to add the id to the name. Pure guess but I assume. Then this is handy because the ls output (because of the -..1) will be in a list. So you can easily do this to process the folders one by one:

ls -Aq1 | grep -Pv '.*\[tmdb-\d+\].*' | \
while read -r level
do
   ...
done

or

ls -Aq1 | \
while read -r level
do
   if ! echo "$level" | grep -Pq '.*\[tmdb-\d+\].*'
   then
      ...
   fi
done