.\" $Id: glob.man,v 1.19 2012/02/29 23:51:34 ksb Exp $ .\" by KsBraunsdorf .\" $Compile: Display%h .\" $Display: ${groff:-groff} -Tascii -man %f |${PAGER:-less} .\" $Display(*): ${groff:-groff} -Tascii -man %f .\" $Install: %b -mDeinstall %o %f && cp %f ${DESTDIR}/usr/local/man/man1/glob.1 .\" $Deinstall: ${rm-rm} -f ${DESTDIR}/usr/local/man/[cm]a[nt]1/glob.1* .TH GLOB 1 LOCAL .SH NAME glob - expand glob expressions into matching filenames .SH SYNOPSIS .ds PN "glob \fI\*(PN\fP [\fB\-rsz\fP] [\fB\-m\fP\~\fImode\fP] [\fIglobs\fP] .br \fI\*(PN\fP \fB\-f\fP [\fB\-rsz\fP] [\fB\-m\fP\~\fImode\fP] [\fIfiles\fP] .br \fI\*(PN\fP \fB\-h\fP .br \fI\*(PN\fP \fB\-V\fP .SH DESCRIPTION The shell expands the wildcard character '*', '?', and the ranges specified in square brackets '[' \fIrange\fP ']' for most application without any issues. When the shell can do the job you should use it. .P In some cases the shell expands a glob into an argument list that is too long for \fBexecve\fP(2). In that case you get a nasty error like: .br .RS ksh: ls: Argument list too long .RE .P \fIGlob\fP outputs the matches on \fIstdout\fP, rather than as an argument vector. Thus any number of input \fIglobs\fP may match a huge list of output filenames. If the \fIglobs\fP themselves will not fit on a command-line you may use \fB\*(PN\fP as a filter, then pass them in a file or on \fIstdin\fP. .P Note that when multiple input patterns match the same filename, that name is replicated in the output. Use \fBoue\fP(1l) to remove any duplicate matches, as required. .P This solves the overflow of the argument list issue when the matches are directed to \fBxargs\fP, \fBxapply\fP, or used as a co-process in a \fBksh\fP script. See the EXAMPLE section below. .SH OPTIONS If the program is called as \fI\*(PN\fP then no options are forced. .TP \fB\-f\fP The glob expression are read as a filter would, rather than from command-line patterns. This means you can pass them on \fIstdin\fP, or from a list of files as you would to \fBcat\fP(1). .TP \fB\-h\fP Print a brief help message. .TP \fB\-m\fP\fImode\fP All matches must match the given \fBinstck\fP(8l) mode specification. Both symbolic and octal modes are allowed, optional bits are represented after a slash. See EXAMPLES below. Always use \fB\-s\fP (or \fB\-r\fP) with this option, unless you have good reason not to. .TP \fB\-r\fP Report non-matching patterns on stderr, rather than passing them along unmatched. .TP \fB\-s\fP Unmatched expressions are completely silent, the also ignores \fB\-r\fP. .TP \fB\-V\fP Show only version information. .TP \fB\-z\fP Output names with terminating NUL characters, like \fBfind\fP(1)'s \-print0 option. Also under \fB\-f\fP reads names in the same format. If you want to input globs from a text file use \fBtr\fP as a filter (see below). .SH EXAMPLES .TP .nf \fB\*(PN\fP /var/spool/mqueue/df/\e* |& while read \-p DF ; do \fI...\fP done .fi Use \fB\*(PN\fP to list all the (possibly thousands) of messages pending in \fBsendmail\fP's queue. Then rune a shell loop to process each one. .TP .nf \fB\*(PN\fP \-s '*.[ch]' |xapply \-f 'indent %1' \- .fi Run the \fBindent\fP(1) program over all the C files in this directory. .TP .nf \fB\*(PN\fP \-f my.pats |xargs rm \-f .fi Remove all the files that match the glob expressions in \fBmy.pats\fP. Remember the crazy \fIeofstr\fP in \fBxargs\fP(1) rules, look out for a file named underscore (\*(lq_\*(rq). .TP .nf \fB\*(PN\fP \-s '*/*/*/' |xapply \-P3 \-f \-5 '\fIprocess\fP' \- \- \- \- \- .fi Make a list of lots of subdirectories, send them to be \fIprocess\fP'd 5 at a time and run three of those in parallel. This show the power gained my using \fBxapply\fP(1l) and \fI\*(PN\fP together. Note that the last instance of \fIprocess\fP may have less than 5 arguments. .TP .nf \fB\*(PN\fP \-sf my.pats | oue | xargs rm \-\- .fi Remove all the files that match the globs, as above, but don't remove the same file more than once. .TP .nf \fB\*(PN\fP \-z \-sf my.zpats | oue \-z | xapply \-zf 'rm \-\- "%q1"' \- .fi Same as the example above, but we think where might be crazy filenames (like ones with newline or spaces in them) so we use NUL termination in the whole pipeline. See below. .TP .nf (\fB\*(PN\fP '*.h' ; \fB\*(PN\fP '*') | oue \-vd .fi Output all the (non-dot) files that \fUdo not\fP match \fB*.h\fP. There is no better way to do this within \fB\*(PN\fP itself. .TP .nf \fB\*(PN\fP '*' | grep \-v '\e.h$' .fi When you can translate the excluding glob into an RE you can use \fBgrep\fP inverse option to filter out the chaff. This is less disk intensive, since \fBoue\fP may open a GDBM file in $TMPDIR to record the hits in the previous version. .TP .nf tr '\en' '\e000'