Using wildcards to exclude files with a certain suffix

bash, linux, wildcard

Solution

I don't think this is doable with only wildcards.

Your command isn't working because it means:

Match everything that has `xyz` followed by whatever you want and it must not end with sequent character: `\`, `.`,`T` and `X`. The second `T` doesn't count as far as what you have inside `[]` is read as a family of character and not as a string as you thought.

You don't either need to 'escape' `.` as long as it has no special meaning inside a wildcard.

At least, this is my knowledge of wildcards.

Problem

I am experimenting with wildcards in bash and tried to list all the files that start with "xyz" but does not end with ".TXT" but getting incorrect results. Here is the command that I tried: ``` $ ls -l xyz*[!\.TXT] ``` It is not listing the files with names "xyz" and "xyzTXT" that I have in my directory. However, it lists "xyz1", "xyz123". It seems like adding `[!\.TXT]` after "xyz*" made the shell look for something that start with "xyz" and has at least one character after it. Any ideas why it is happening and how to correct this command? I know it can be achieved using other commands but I am especially interested in knowing why it is failing and if it can done just using wildcards.

Original source