Bash - pathname expansion (Filename expansion)

About

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

Example

Asterix

  • 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

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