1glob(n)                      Tcl Built-In Commands                     glob(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       glob - Return names of files that match patterns
9

SYNOPSIS

11       glob ?switches? pattern ?pattern ...?
12_________________________________________________________________
13
14

DESCRIPTION

16       This  command  performs  file name ``globbing'' in a fashion similar to
17       the csh shell.  It returns a list of the files whose names match any of
18       the pattern arguments.
19
20       If  the initial arguments to glob start with - then they are treated as
21       switches.  The following switches are currently supported:              │
22
23       -directory directory                                                    │
24              Search for files which match the given patterns starting in  the │
25              given  directory.   This  allows  searching of directories whose │
26              name contains glob-sensitive  characters  without  the  need  to │
27              quote  such  characters explicitly.  This option may not be used │
28              in conjunction with -path, which is used to allow searching  for │
29              complete file paths whose names may contain glob-sensitive char‐ │
30              acters.                                                          │
31
32       -join                                                                   
33              The remaining pattern arguments are treated as a single  pattern │
34              obtained by joining the arguments with directory separators.
35
36       -nocomplain
37              Allows an empty list to be returned without error;  without this
38              switch an error is returned if the result list would be empty.   │
39
40       -path pathPrefix                                                        │
41              Search for files with the given pathPrefix where the rest of the │
42              name  matches  the  given  patterns.   This allows searching for │
43              files with names similar to a given file (as opposed to a direc‐ │
44              tory)  even  when  the  names contain glob-sensitive characters. │
45              This option may not be used in conjunction with -directory.  For │
46              example, to find all files with the same root name as $path, but │
47              differing extensions, you should use glob -path  [file  rootname 
48              $path]  .* which will work even if $path contains numerous glob- │
49              sensitive characters.                                            │
50
51       -tails                                                                  
52              Only return the part of each file found which follows  the  last │
53              directory  named  in any -directory or -path path specification. │
54              Thus glob -tails -directory $dir *  is  equivalent  to  set  pwd 
55              [pwd]  ;  cd  $dir ; glob *; cd $pwd.  For -path specifications, │
56              the returned names will include the last path segment,  so  glob 
57              -tails  -path  [file  rootname  ~/foo.tex] .*  will return paths │
58              like foo.aux foo.bib foo.tex etc.                                │
59
60       -types typeList                                                         │
61              Only list files or directories which match typeList,  where  the │
62              items  in  the  list have two forms.  The first form is like the │
63              -type option of the Unix find command: b (block special file), c
64              (character special file), d (directory), f (plain file), l (sym‐ │
65              bolic link), p (named pipe), or s (socket), where multiple types │
66              may  be specified in the list.  Glob will return all files which │
67              match at least one of the types given.  Note that symbolic links │
68              will  be returned both if -types l is given, or if the target of │
69              a link matches the requested type.  So, a link  to  a  directory │
70              will be returned if -types d was specified.                      │
71
72              The  second  form specifies types where all the types given must │
73              match.  These are r, w, x as  file  permissions,  and  readonly, │
74              hidden  as  special  permission  cases.  On the Macintosh, MacOS │
75              types and creators are also supported, where any item  which  is │
76              four  characters long is assumed to be a MacOS type (e.g. TEXT). │
77              Items which are of the form {macintosh type XXXX} or  {macintosh
78              creator XXXX} will match types or creators respectively.  Unrec‐ │
79              ognized types, or specifications of  multiple  MacOS  types/cre‐ │
80              ators will signal an error.                                      │
81
82              The  two  forms  may be mixed, so -types {d f r w} will find all │
83              regular files OR directories that have both read AND write  per‐ │
84              missions.  The following are equivalent:                         │
85                            glob -type d *                                     
86                            glob */                                            
87              except that the first case doesn't return the trailing ``/'' and │
88              is more platform independent.                                    │
89
90       --     Marks the end of switches.  The argument following this one will
91              be treated as a pattern even if it starts with a -.
92
93       The  pattern arguments may contain any of the following special charac‐
94       ters:
95
96       ?         Matches any single character.
97
98       *         Matches any sequence of zero or more characters.
99
100       [chars]   Matches any single character in chars.  If chars  contains  a
101                 sequence  of  the form a-b then any character between a and b
102                 (inclusive) will match.
103
104       \x        Matches the character x.
105
106       {a,b,...} Matches any of the strings a, b, etc.
107
108       On Unix, as with csh, a ``.'' at the beginning of a file's name or just
109       after a ``/'' must be matched explicitly or with a {} construct, unless
110       the ``-types hidden'' flag is given (since ``.'' at the beginning of  a
111       file's  name  indicates  that it is hidden).  On other platforms, files
112       beginning with a ``.'' are handled no differently to any others, except
113       the  special directories ``.'' and ``..'' which must be matched explic‐
114       itly (this is to avoid a recursive pattern like ``glob -join * * *  *''
115       from  recursing  up the directory hierarchy as well as down).  In addi‐
116       tion, all ``/'' characters must be matched explicitly.
117
118       If the first character in a pattern is ``~'' then it refers to the home
119       directory  for  the user whose name follows the ``~''.  If the ``~'' is
120       followed immediately by ``/'' then the value of  the  HOME  environment
121       variable is used.
122
123       The glob command differs from csh globbing in two ways.  First, it does
124       not sort its result list (use the lsort command if you  want  the  list
125       sorted).   Second,  glob  only returns the names of files that actually
126       exist;  in csh no check for existence is made unless a pattern contains
127       a ?, *, or [] construct.
128
129       When the glob command returns relative paths whose filenames start with
130       a tilde ``~'' (for example through glob * or glob -tails, the  returned
131       list  will  not  quote  the tilde with ``./''.  This means care must be
132       taken if those names are later to be used with file join, to avoid them
133       being  interpreted  as  absolute  paths pointing to a given user's home
134       directory.
135

PORTABILITY ISSUES

137       Unlike other Tcl commands that will  accept  both  network  and  native
138       style  names  (see  the filename manual entry for details on how native
139       and network names are specified), the glob command only accepts  native
140       names.
141
142       Windows
143              For  Windows  UNC names, the servername and sharename components
144              of the path may not contain ?, *, or [] constructs.  On  Windows
145              NT,  if pattern is of the form ``~username@domain'' it refers to
146              the home directory of the user whose account information resides
147              on  the  specified  NT  domain  server.  Otherwise, user account
148              information is obtained from the local computer.  On Windows  95
149              and  98,  glob  accepts patterns like ``.../'' and ``..../'' for
150              successively higher up parent directories.
151
152              Since the backslash character has a special meaning to the  glob
153              command,  glob patterns containing Windows style path separators
154              need special care. The  pattern  C:\\foo\\*  is  interpreted  as
155              C:\foo\*  where \f will match the single character f and \* will
156              match the single character * and will not be  interpreted  as  a
157              wildcard  character.  One solution to this problem is to use the
158              Unix style forward slash as  a  path  separator.  Windows  style
159              paths can be converted to Unix style paths with the command file
160              join $path (or file normalize $path in Tcl 8.4).
161
162       Macintosh
163              When using the options, -directory, -join or -path, glob assumes
164              the  directory  separator for the entire pattern is the standard
165              ``:''.  When not using these options, glob examines each pattern
166              argument and uses ``/'' unless the pattern contains a ``:''.
167

EXAMPLES

169       Find all the Tcl files in the current directory:
170              glob *.tcl
171
172       Find  all  the  Tcl files in the user's home directory, irrespective of
173       what the current directory is:
174              glob -directory ~ *.tcl
175
176       Find all subdirectories of the current directory:
177              glob -type d *
178
179       Find all files whose name contains an "a", a "b" or the sequence "cde":
180              glob -type f *{a,b,cde}*
181
182

SEE ALSO

184       file(n)
185
186

KEYWORDS

188       exist, file, glob, pattern
189
190
191
192Tcl                                   8.3                              glob(n)
Impressum