Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/glob.n @ 43

Last change on this file since 43 was 25, checked in by landauf, 16 years ago

added tcl to libs

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