Bash - pathname expansion (Filename expansion)


pathname or filename expansion is the possibility to define filename via globbing wildcard.



  • asterix matches every filename in a given directory.
echo * # will list all files in the current directory
echo t* # will list all files that start with t

Question Mark

  • ? matches a single character
echo t?.sh # will list the file that start with t and have two characters

If there is no match, the expression is just echoed

Double Asterix

The globstar parameters should be set to enable Glob - Globbing (Wildcard expression)

shopt -s globstar
ls **/
shopt -u globstar
ls **/

If followed by a /, two adjacent *s will match only directories and subdirectories.


braces globbing is supported on the last bash version

ls -l {b*,c*,*est*}

Not to confound with brace expansion that generates string.

Documentation / Reference

man 7 glob | col -b > glob.txt

Powered by ComboStrap