O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.3. Using [ . . . ] and [ ! . . . ]

Use [...] to match any characters inside the brackets. This method also supports ranges by separating the range with a dash. To list all filenames that start with an ‘i’ or ‘o’:

						$ ls [io]* 
inetd.conf initrunlvl 
inputrc    issue 
info-dir   inittab 
ioctl.save issue.net
					

To match filenames that begin with ‘log.’, followed by a single number, followed by any other character. The [0–9] means any single number. The asterisk takes care of multiple numbers:

						$ ls log.[0-9]* 
log.0323  log.0324 
log.0325  log.0326
					

To list all filenames that have the same criteria as above but with no numbers, use the negation symbol (!) inside the bracket. [!0–9]* means it must not start with a digit.

						$ ls log.[!0-9]* 
log.sybase
					

To match ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required