4.2. Using the ?

Use the ? to match any single character. Here we list filenames where the first two characters can be any character, followed by an ‘R’, followed by any string:

						$ ls ??R* 
BAREAD
					

In the following example, we list files that start with ‘conf’, followed by any two characters, followed by ‘.log’:

						$ ls conf.??.log 
conf12.log conf.23.log 
conf25.log
					

To match all filenames that start with ‘f’, followed by any two characters, followed by any string; the end character must be an ‘s’:

						$ ls f??*s 
ftpaccess      ftpconversions 
ftpgroups      ftphosts 
ftpusers
					

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.