Globbing is what lets you use a pattern to match one or more files:
% rm *.*
% ls * adb.1 dd.1 ld.so.1 addbib.1 ed.1 ldd.1 adjacentscreens.1 edit.1 od.1v admin.1 fdformat.1 pdp11.1 cd.1 id.1v rdist.1 cdc.1 ld.1 sdiff.1v[show all files that end in ".1v"]
% ls *.1v id.1v od.1v sdiff.1v[show all files that start with "a" and have a "b"]
% ls a*b* adb.1 addbib.1
% ls ?????* addbib.1 fdformat.1 pdp11.1 adjacentscreens.1 id.1v rdist.1 admin.1 ld.so.1 sdiff.1v cdc.1 ldd.1 edit.1 od.1v[show all files with a 2-character extension]
% ls *.?? id.1v od.1v sdiff.1v[show all files whose third letter is "d"]
% ls ??d* addbib.1 ldd.1
% ls [ae]* adb.1 adjacentscreens.1 ed.1 addbib.1 admin.1 edit.1[show all files that don't start with "a" or "e"]
% ls [^ae]* cd.1 fdformat.1 ld.so.1 pdp11.1 cdc.1 id.1v ldd.1 rdist.1 dd.1 ld.1 od.1v sdiff.1v[show all files that have a "c" or "h" extension]
% ls *.[ch]
% ls z* ls: No match.
% set nonomatch % ls z* z* not found
The final matching construct is only available in csh and its derivatives, and is not subject to the "No match" problems:
% ls {a,b}{c,d}* adb.1 adjacentscreens.1 addbib.1 admin.1[show all files that start with "ed" or "ld"]
% ls {ed,ld}* ed.1 edit.1 ld.1 ld.so.1 ldd.1[show all files that have a "cc" or "hh" extension]
% ls *.{cc,hh}
Since the curly brackets don't pay any attention to the available files, you can also use them to generate strings (or count in base 3 ;-):
% echo {0,1,2}{0,1,2}{0,1,2} | fmt -36 000 001 002 010 011 012 020 021 022 100 101 102 110 111 112 120 121 122 200 201 202 210 211 212 220 221 222
Up to the TTTT index
Tuesday Tiny Techie Tips are all © Copyright 1996-1997 by Jeff Youngstrom. Please ask permission before reproducing any of this material.