Wild-cards and file name completion

The wild card characters are * and ?. The symbol * matches any string and ? matches any single character. For example, the following command lists all files with names starting with the string hw in the current directory:

ls hw*

The following command lists all files ending with .java in all subdirectories of the current directory.

ls */*.java

These characters are simple regular expressions. Regular expressions are a powerful way to express text patterns. You will encounter them again in your explorations in future courses and in life!

The shell has a file name completion feature by which you can avoid typing long file and directory names. Suppose you have a directory named horriblylongname and you wanted tocd to this directory. You can type cd horr and then hit the TAB key and the shell will attempt to find a filename starting with the string horr. If there is a unique match, the shell will complete the file name. If there is more than one file or directory that has a name starting with the prefix horr, then the shell will beep. Hitting the TAB key again will show you all the files or directories that start with the prefix horr. Now you can type a few more characters until the prefix is unique so the shell can complete the filename for you. The file completion feature is very handy and saves the user a lot of typing and errors.