17.4 Identifying and Working with File Types 265
sneakers.txt
You’ll probably use the asterisk (*) most frequently when you’re searching. The asterisk will search
out everything that matches the pattern you’re looking for. So even by typing:
ls *.txt
or:
ls sn*
you’d find sneakers.txt – except that as time goes on, there will be more text files, and they’ll all
show up because they match the pattern you’re searching for.
Ithelps,then,tonarrowyoursearchasmuchaspossible.
One way to narrow the search might be to use the question mark symbol (?). Like the asterisk, using
? can help locate a file matching a search pattern.
In this case, though, ? is useful for matching a single character – so if you were searching for
sneaker?.txt,you’dgetsneakers.txt as a result – and/or sneakerz.txt, if there were such
a filename.
When an asterisk, for example, just happens to be part of a filename, such as might be the case if the
file sneakers.txt was called sneak*.txt,that’s when regular expressions can come in handy.
Regular expressions are more complex than the straightforward asterisk or question mark.
Using the backslash (\), you can specify that you don’twanttosearchouteverything by using the
asterisk, but you’re instead looking for a file with an asterisk in the name.
If the file is called sneak*.txt, then, type:
sneak\*.txt
Here is a brief list of wildcards and regular expressions:
* – Matches all characters
? – Matches one character in a string (such as sneaker?.txt)
\* – Matches the * character
\? – Matches the ? character
\) – Matches the ) character
Comments to this Manuals