list all the files that dont match pattern in bash list all the files that dont match pattern in bash unix unix

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)


With find command:

find -type f ! \( -name '*abc*.txt' -o -name '*xyz*.txt' \)


You can use the --hide=PATTERN option with ls. In your case it would be

ls --hide="*abc*.txt" --hide="*xyz*.txt"