Wildcards

What are the bash wildcards? (e.g *,?..)

Using bash wildcards

I bookmark for future reference, because my memory is like 64k.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

That’s fair… it’s all the memory you’ll ever need… or so he says.

Good luck.

giaslamo wrote:
> ‘Using bash wildcards’
> (http://www.shell-tips.com/2006/11/04/using-bash-wildcards/)
>
> I bookmark for future reference, because my memory is like 64k.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIse3N3s42bA80+9kRAto5AJ96tLtV5mj4N+JI2dysY1XheiRA/gCfVDYe
VFQMw6rvymUNa2vttHP4OKQ=
=9FBQ
-----END PGP SIGNATURE-----

There are quite a few options for wildcards in Bash. I’m not sure how comprehensive this list is, but it’s at least a starting point:

  • (asterisk) zero or more characters

? (question mark) one character

[abcde] - any one of the character from the contents of square brackets

[a-e] - any one character in the range defined either side of the dash within square brackets

!abcde] or !a-e] modifies the two previous examples with “not”

{suse,linux} any one string from the options listed in curly brackets

Strictly speaking that last one {suse,linux} isn’t a wildcard but brace expansion. What is the difference? Brace expansion works even if there is no match. Say you have file1 and file3 in a directory.

echo file[1-3]

will get you file1 file3, but

echo file{1,2,3}

will get you file1 file2 file3

You can read all about brace expansion in the man page.