1

I have two files:

AAAAA_AAAA_BBBBBBBB_SSSSSS
AAAAA_BBBBBBBB_SSSSSS

I want only the file with two underscores be shown.

I used:

ls -1 ^?*_?*_?*$

I got:

ls: ?*_?*_?*$: No such file or directory

Why? And what can be a solution?

wjandrea
  • 14,236
  • 4
  • 48
  • 98
Josef Klimuk
  • 1,596

1 Answers1

2

You've mixed up shell globs and regular expression syntax - and come up with something that's not valid in either.

If you want to use a regex based tool, try find e.g.

find . -maxdepth 1 -regex '^[^_]*_[^_]*_[^_]*$'
steeldriver
  • 136,215
  • 21
  • 243
  • 336