3

I was practicing the use of wildcards today .. that was a lot of fun.
The most complex thing that worked out exactly as I was expecting was:
ls [![:digit:]]*[a-z][0-9][0-9][0-9][aA-zZ]*[![:digit:]]

But I didn't actually manage to exclude a string.
How can I list only files which do not contain "test"?
Here some examples what I've tried already:

ls *!("test")*
ls !("test")
ls !=*"test"*
ls !(*"test"*)
ls *^test*
ls *(^test)*
ls (^test)*
ls !test*
ls !*test*
ls *!test*
ls !{test}
ls !*{test}*
ls *!{test}*
Heiko
  • 261
  • 3
  • 9

2 Answers2

4

In Bash:

$ shopt -s extglob
$ touch a b c test
$ ls !(*test*)
a  b  c
1

Alternatively and portably you can use find command as following:

find -type f ! -name '*test*'
αғsнιη
  • 41,407