Difference between * and ?* glob in Bash

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 and xfile.txt and try to list them with ls ?*file.txt or ls *file.txt.

One real case scenario when I use such construct is to list hidden files. Very often I just do

ls .??*

Double question marks are here to prevent listing the current directory . and the parent directory .., like it would be with a simpler form ls .*.


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 is ls {..?,.[!.]}*, but usually that is too much to type for me.


Where did you get that definition from, of to what kind of expression do you refer?

If we talk about shell expressions, both characters can be used alone, but the definition for ? doesn't match, as then it always matches one character and not one or zero.

If we talk about regular expressions, both are operators that are placed after an expression. So in "?*" would have to be placed after something else.

Tags:

Bash

Wildcards