Back to CFM home             Brown University





Examples of using wildcard characters

To match any number of characters in a filename:

   ls *.txt

This lists all the files in the current directory that have the extension .txt - so Help.txt as well as nonsense.txt would be listed.


To match any single character in a filename:

   cat memo? > mymemos

This concatenates all files with the filename

   memo0 -> memo9
   memoa -> memoz
   memoA -> memoZ

and places their contents in the file mymemos.


To remove a range of files:

   rm part[1-3]

This removes files part1, part2 and part3 from the current directory. If no files are found that match these names the message

   No match

is displayed.


To look for an expression in a file:

   grep '[Jj]ohn' < addresses

This looks for and, if found, displays the lines containing the name john or John in the file addresses.

Notice that the expression to be searched for is enclosed in 'quotes' to prevent the '[' character being interpreted by the shell.


[Home] [Search] [Index]