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 the
17       csh shell.  It returns a list of the files whose names match any of the
18       pattern  arguments.   No particular order is guaranteed in the list, so
19       if a sorted list is required the caller should use lsort.
20
21       If the initial arguments to glob start with - then they are treated  as
22       switches.  The following switches are currently supported:
23
24       -directory directory
25              Search  for files which match the given patterns starting in the
26              given directory.  This allows  searching  of  directories  whose
27              name  contains  glob-sensitive  characters  without  the need to
28              quote such characters explicitly.  This option may not  be  used
29              in  conjunction with -path, which is used to allow searching for
30              complete file paths whose names may contain glob-sensitive char‐
31              acters.
32
33       -join  The  remaining  pattern  arguments, after option processing, are
34              treated as a single pattern obtained by  joining  the  arguments
35              with directory separators.
36
37       -nocomplain
38              Allows an empty list to be returned without error;  without this
39              switch an error is returned if the result list would be empty.
40
41       -path pathPrefix
42              Search for files with the given pathPrefix where the rest of the
43              name  matches  the  given  patterns.   This allows searching for
44              files with names similar to a given file (as opposed to a direc‐
45              tory)  even  when  the  names contain glob-sensitive characters.
46              This option may not be used in conjunction with -directory.  For
47              example, to find all files with the same root name as $path, but
48              differing extensions, you should use glob -path  [file  rootname
49              $path]  .* which will work even if $path contains numerous glob-
50              sensitive characters.
51
52       -tails 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 explicitly
114       (this is to avoid a recursive pattern like “glob -join * *  *  *”  from
115       recursing up the directory hierarchy as well as down). In addition, all
116       “/” 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 fol‐
120       lowed immediately by “/” then the value of the HOME  environment  vari‐
121       able 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 taken
132       if those names are later to be used with file join, to avoid them being
133       interpreted  as  absolute  paths pointing to a given user's home direc‐
134       tory.
135

PORTABILITY ISSUES

137       Windows For Windows UNC names, the servername and sharename  components
138       of  the path may not contain ?, *, or [] constructs.  On Windows NT, if
139       pattern is of the form “~username@domain”, it refers to the home direc‐
140       tory  of the user whose account information resides on the specified NT
141       domain server.  Otherwise, user account information  is  obtained  from
142       the  local  computer.  On Windows 95 and 98, glob accepts patterns like
143       “.../” and “..../” for successively higher up parent directories.
144
145       Since the backslash character has a special meaning to  the  glob  com‐
146       mand,  glob patterns containing Windows style path separators need spe‐
147       cial care. The pattern C:\\foo\\* is interpreted as C:\foo\*  where  \f
148       will  match the single character f and \* will match the single charac‐
149       ter * and will not be interpreted as a wildcard character. One solution
150       to  this problem is to use the Unix style forward slash as a path sepa‐
151       rator. Windows style paths can be converted to Unix  style  paths  with
152       the command file join $path (or file normalize $path in Tcl 8.4).
153

EXAMPLES

155       Find all the Tcl files in the current directory:
156              glob *.tcl
157
158       Find  all  the  Tcl files in the user's home directory, irrespective of
159       what the current directory is:
160              glob -directory ~ *.tcl
161
162       Find all subdirectories of the current directory:
163              glob -type d *
164
165       Find all files whose name contains an “a”, a “b” or the sequence “cde”:
166              glob -type f *{a,b,cde}*
167
168

SEE ALSO

170       file(n)
171
172

KEYWORDS

174       exist, file, glob, pattern
175
176
177
178Tcl                                   8.3                              glob(n)
Impressum