Your filename globbing pattern is almost correct for detecting names that have at least two underscores, but you are forcing the names to have an underscore at the very end.
You should be ok if you just add a final
* at the end of the pattern:
$ find . -name '*_*_*'
To explicitly not match names with more than two underscores:
$ find . -name '*_*_*' ! -name '*_*_*_*'
The second part here,
-name '*_*_*_*', would match any name with three or more underscores, and the preceding
! would negate the sense of the match.
Note that a
find expression without
-type will match the names of any type of file, that is, it may match the names of directories, named pipes, sockets, device files etc.
To additionally only match regular files add
-type f, or you could use
! -type d to avoid matching directory names. Use
-type l to to match symbolic links.
find command may look like:
find . -type l -name '*_*_*' ! -name '*_*_*_*' -delete
This would remove symbolic links found in the current directory, or below, whose names include exactly two underscores. The targets of the symbolic links would not be affected, unless they themselves are symbolic links with names that match the criteria and are located under the current directory.