[ ] and { }


[ ] - Match Single Character

We can denote multiple files by using the "[" and "]" characters.

Given the following directory listing...

linux3 [6]# ls
file.a  file.cgi  file.html  file.lib  file.tk   file.z
file.c  file.h    file.l     file.pl   file.txt
linux3 [7]#

If I want to list just the *.c and *.h files I could do it in this fashion...

linux3 [8]# ls *.[c,h]
file.c  file.h
linux3 [9]#

Or you can specify ranges of values, such as...

linux3 [10]# ls *.[a-z]
file.a  file.c  file.h  file.l  file.z
linux3 [11]#

{ } - Match Multiple Characters

We can also denote multiple files by using the "{" and "}" characters. This is the multiple character version of the previous example.

Again given the following directory listing...

linux3 [11]# ls
file.a  file.cgi  file.html  file.lib  file.tk   file.z
file.c  file.h    file.l     file.pl   file.txt
linux3 [12]#

If I want to list just the *.cgi, *.pl and *.tk files I could do it in this fashion...

linux3 [12]# ls *.{cgi,pl,tk}
file.cgi  file.pl  file.tk
linux3 [13]#

I find this very helpful when trying to open up an entire project that consists of multiple files in emacs, to issue a command like so... "emacs *.{c,h,txt} &"


Daniel J. Hood
Last modified: Sat Jan 18 19:05:55 EST 2003