list all the files that dont match pattern in bash
You can use an extended glob, such as the following:
!(*@(abc|xyz)*.txt)
In ksh, this works by default, whereas in bash you need to first enable a shell option:
shopt -s extglob
!
negates the match and @
matches any of the pipe-separated patterns.
This pattern expands to the list of files that don't match *abc*.txt
or *xyz*.txt
, so you can pass it to another command to see the result, e.g. printf
:
printf '%s\n' !(*@(abc|xyz)*.txt)