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 ...?
12______________________________________________________________________________
13

DESCRIPTION

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

WINDOWS PORTABILITY ISSUES

141       For  Windows  UNC names, the servername and sharename components of the
142       path may not contain ?, *, or [] constructs. On Windows NT, if  pattern
143       is  of  the form “~username@domain”, it refers to the home directory of
144       the user whose account information resides on the specified  NT  domain
145       server.  Otherwise, user account information is obtained from the local
146       computer.
147
148       Since the backslash character has a special meaning to  the  glob  com‐
149       mand,  glob patterns containing Windows style path separators need spe‐
150       cial care. The pattern “C:\\foo\\*” is interpreted as “C:\foo\*”  where
151\f” will match the single character “f” and “\*” will match the single
152       character “*” and will not be interpreted as a wildcard character.  One
153       solution  to  this  problem is to use the Unix style forward slash as a
154       path separator. Windows style paths can  be  converted  to  Unix  style
155       paths with the command “file join $path” or “file normalize $path”.
156

EXAMPLES

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

SEE ALSO

176       file(n)
177

KEYWORDS

179       exist, file, glob, pattern
180
181
182
183Tcl                                   8.3                              glob(n)
Impressum