*
is roughly a wild card character with a unlimited amount of length.?
is roughly a wild card character for one or zero length.
Is there a difference between using *
vs ?*
when searching for strings in bash
?
bashwildcards
*
is roughly a wild card character with a unlimited amount of length.?
is roughly a wild card character for one or zero length.Is there a difference between using *
vs ?*
when searching for strings in bash
?
Best Answer
The difference is that in
bash
(as you tagged the question)*
matches any string with length zero or more characters, while?*
matches a string with at least 1 character. Consider for example two files:file.txt
andxfile.txt
and try to list them withls ?*file.txt
orls *file.txt
.One real case scenario when I use such construct is to list hidden files. Very often I just do
Double question marks are here to prevent listing the current directory
.
and the parent directory..
, like it would be with a simpler formls .*
.I need to point here that my
.??*
is not perfect; for example filenames with only two characters, like.f
, don't match this pattern. More reliable solution isls {..?,.[!.]}*
, but usually that is too much to type for me.