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?
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?
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 '^[^_]*_[^_]*_[^_]*$'
ls
command itself doesn't interpret the pattern - that's done by the shell (and it uses a much simpler glob syntax ) – steeldriver Jan 11 '18 at 06:01