Debian Codegraph @

doc/glob.n

raw
1 '\"
2 '\" Copyright (c) 1993 The Regents of the University of California.
3 '\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4 '\"
5 '\" See the file "license.terms" for information on usage and redistribution
6 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7 .TH glob n 8.3 Tcl "Tcl Built-In Commands"
8 .so man.macros
9 .BS
10 '\" Note: do not modify the .SH NAME line immediately below!
11 .SH NAME
12 glob \- Return names of files that match patterns
13 .SH SYNOPSIS
14 \fBglob \fR?\fIswitches\fR? ?\fIpattern ...\fR?
15 .BE
16 .SH DESCRIPTION
17 .PP
18 This command performs file name
19 .QW globbing
20 in a fashion similar to
21 the csh shell or bash shell.
22 It returns a list of the files whose names match any
23 of the \fIpattern\fR arguments. No particular order is guaranteed
24 in the list, so if a sorted list is required the caller should use
25 \fBlsort\fR.
26 .SS OPTIONS
27 .PP
28 If the initial arguments to \fBglob\fR start with \fB\-\fR then
29 they are treated as switches. The following switches are
30 currently supported:
31 .TP
32 \fB\-directory\fR \fIdirectory\fR
33 .
34 Search for files which match the given patterns starting in the given
35 \fIdirectory\fR. This allows searching of directories whose name
36 contains glob-sensitive characters without the need to quote such
37 characters explicitly. This option may not be used in conjunction with
38 \fB\-path\fR, which is used to allow searching for complete file paths
39 whose names may contain glob-sensitive characters.
40 .TP
41 \fB\-join\fR
42 .
43 The remaining pattern arguments, after option processing, are treated
44 as a single pattern obtained by joining the arguments with directory
45 separators.
46 .TP
47 \fB\-nocomplain\fR
48 .
49 Allows an empty list to be returned without error; without this
50 switch an error is returned if the result list would be empty.
51 .TP
52 \fB\-path\fR \fIpathPrefix\fR
53 .
54 Search for files with the given \fIpathPrefix\fR where the rest of the name
55 matches the given patterns. This allows searching for files with names
56 similar to a given file (as opposed to a directory) even when the names
57 contain glob-sensitive
58 characters. This option may not be used in conjunction with
59 \fB\-directory\fR. For example, to find all files with the same root name
60 as $path, but differing extensions, you should use
61 .QW "\fBglob \-path [file rootname $path] .*\fR"
62 which will work even if \fB$path\fR contains
63 numerous glob-sensitive characters.
64 .TP
65 \fB\-tails\fR
66 .
67 Only return the part of each file found which follows the last directory
68 named in any \fB\-directory\fR or \fB\-path\fR path specification.
69 Thus
70 .QW "\fBglob \-tails \-directory $dir *\fR"
71 is equivalent to
72 .QW "\fBset pwd [pwd]; cd $dir; glob *; cd $pwd\fR" .
73 For \fB\-path\fR specifications, the returned names will include the last
74 path segment, so
75 .QW "\fBglob \-tails \-path [file rootname ~/foo.tex] .*\fR"
76 will return paths like \fBfoo.aux foo.bib foo.tex\fR etc.
77 .TP
78 \fB\-types\fR \fItypeList\fR
79 .
80 Only list files or directories which match \fItypeList\fR, where the items
81 in the list have two forms. The first form is like the \-type option of
82 the Unix find command:
83 \fIb\fR (block special file),
84 \fIc\fR (character special file),
85 \fId\fR (directory),
86 \fIf\fR (plain file),
87 \fIl\fR (symbolic link),
88 \fIp\fR (named pipe),
89 or \fIs\fR (socket), where multiple types may be specified in the list.
90 \fBGlob\fR will return all files which match at least one of the types given.
91 Note that symbolic links will be returned both if \fB\-types l\fR is given,
92 or if the target of a link matches the requested type. So, a link to
93 a directory will be returned if \fB\-types d\fR was specified.
94 .RS
95 .PP
96 The second form specifies types where all the types given must match.
97 These are \fIr\fR, \fIw\fR, \fIx\fR as file permissions, and
98 \fIreadonly\fR, \fIhidden\fR as special permission cases. On the
99 Macintosh, macOS types and creators are also supported, where any item
100 which is four characters long is assumed to be a macOS type
101 (e.g. \fBTEXT\fR). Items which are of the form \fI{macintosh type XXXX}\fR
102 or \fI{macintosh creator XXXX}\fR will match types or creators
103 respectively. Unrecognized types, or specifications of multiple macOS
104 types/creators will signal an error.
105 .PP
106 The two forms may be mixed, so \fB\-types {d f r w}\fR will find all
107 regular files OR directories that have both read AND write permissions.
108 The following are equivalent:
109 .PP
110 .CS
111 \fBglob \-type d *\fR
112 \fBglob */\fR
113 .CE
114 .PP
115 except that the first case doesn't return the trailing
116 .QW /
117 and is more platform independent.
118 .RE
119 .TP
120 \fB\-\|\-\fR
121 .
122 Marks the end of switches. The argument following this one will
123 be treated as a \fIpattern\fR even if it starts with a \fB\-\fR.
124 .SS "GLOBBING PATTERNS"
125 .PP
126 The \fIpattern\fR arguments may contain any of the following
127 special characters, which are a superset of those supported by
128 \fBstring match\fR:
129 .TP 10
130 \fB?\fR
131 .
132 Matches any single character.
133 .TP 10
134 \fB*\fR
135 .
136 Matches any sequence of zero or more characters.
137 .TP 10
138 \fB[\fIchars\fB]\fR
139 .
140 Matches any single character in \fIchars\fR. If \fIchars\fR
141 contains a sequence of the form \fIa\fB\-\fIb\fR then any
142 character between \fIa\fR and \fIb\fR (inclusive) will match.
143 .TP 10
144 \fB\e\fIx\fR
145 .
146 Matches the character \fIx\fR.
147 .TP 10
148 \fB{\fIa\fB,\fIb\fB,\fI...\fR}
149 .
150 Matches any of the sub-patterns \fIa\fR, \fIb\fR, etc.
151 .PP
152 On Unix, as with csh, a
153 .QW . \|
154 at the beginning of a file's name or just after a
155 .QW /
156 must be matched explicitly or with a {} construct, unless the
157 \fB\-types hidden\fR flag is given (since
158 .QW . \|
159 at the beginning of a file's name indicates that it is hidden). On
160 other platforms, files beginning with a
161 .QW . \|
162 are handled no differently to any others, except the special directories
163 .QW . \|
164 and
165 .QW .. \|
166 which must be matched explicitly (this is to avoid a recursive pattern like
167 .QW "glob \-join * * * *"
168 from recursing up the directory hierarchy as well as down). In addition, all
169 .QW /
170 characters must be matched explicitly.
171 .LP
172 If the first character in a \fIpattern\fR is
173 .QW ~
174 then it refers to the home directory for the user whose name follows the
175 .QW ~ .
176 If the
177 .QW ~
178 is followed immediately by
179 .QW /
180 then the value of the HOME environment variable is used.
181 .PP
182 The \fBglob\fR command differs from csh globbing in two ways.
183 First, it does not sort its result list (use the \fBlsort\fR
184 command if you want the list sorted).
185 Second, \fBglob\fR only returns the names of files that actually
186 exist; in csh no check for existence is made unless a pattern
187 contains a ?, *, or [] construct.
188 .LP
189 When the \fBglob\fR command returns relative paths whose filenames
190 start with a tilde
191 .QW ~
192 (for example through \fBglob *\fR or \fBglob \-tails\fR, the returned
193 list will not quote the tilde with
194 .QW ./ .
195 This means care must be taken if those names are later to
196 be used with \fBfile join\fR, to avoid them being interpreted as
197 absolute paths pointing to a given user's home directory.
198 .SH "WINDOWS PORTABILITY ISSUES"
199 .PP
200 For Windows UNC names, the servername and sharename components of the path
201 may not contain ?, *, or [] constructs. On Windows NT, if \fIpattern\fR is
202 of the form
203 .QW \fB~\fIusername\fB@\fIdomain\fR ,
204 it refers to the home
205 directory of the user whose account information resides on the specified NT
206 domain server. Otherwise, user account information is obtained from
207 the local computer.
208 .PP
209 Since the backslash character has a special meaning to the glob
210 command, glob patterns containing Windows style path separators need
211 special care. The pattern
212 .QW \fIC:\e\efoo\e\e*\fR
213 is interpreted as
214 .QW \fIC:\efoo\e*\fR
215 where
216 .QW \fI\ef\fR
217 will match the single character
218 .QW \fIf\fR
219 and
220 .QW \fI\e*\fR
221 will match the single character
222 .QW \fI*\fR
223 and will not be
224 interpreted as a wildcard character. One solution to this problem is
225 to use the Unix style forward slash as a path separator. Windows style
226 paths can be converted to Unix style paths with the command
227 .QW "\fBfile join\fR \fB$path\fR"
228 or
229 .QW "\fBfile normalize\fR \fB$path\fR" .
230 .SH EXAMPLES
231 .PP
232 Find all the Tcl files in the current directory:
233 .PP
234 .CS
235 \fBglob\fR *.tcl
236 .CE
237 .PP
238 Find all the Tcl files in the user's home directory, irrespective of
239 what the current directory is:
240 .PP
241 .CS
242 \fBglob\fR \-directory ~ *.tcl
243 .CE
244 .PP
245 Find all subdirectories of the current directory:
246 .PP
247 .CS
248 \fBglob\fR \-type d *
249 .CE
250 .PP
251 Find all files whose name contains an
252 .QW a ,
253 a
254 .QW b
255 or the sequence
256 .QW cde :
257 .PP
258 .CS
259 \fBglob\fR \-type f *{a,b,cde}*
260 .CE
261 .SH "SEE ALSO"
262 file(n)
263 .SH KEYWORDS
264 exist, file, glob, pattern
265 '\" Local Variables:
266 '\" mode: nroff
267 '\" End: