Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help
next up previous contents
Next: Redirection and Pipes Up: Shell Commands Previous: The Command History &

Filename Completion & Wildcards

The program wc counts the number of lines, words and letters in any files it is given. Suppose we have two files averylongname, hissillyname and we wish to run wc with these names as arguments

wc averylongname hissillyname

It is tedious to type out long filenames like this in full. Instead, we can use filename completion. To use this you type enough of the file name to specify the file uniquely and then press the escape key twice <ESC><ESC>. The shell will then try and type in the rest of the file name for you if it can work out which file you want. So we might type

wc aver<TAB><TAB>

and the shell would complete the name to

wc averylongname

We then add the characters hissi<TAB><TAB> and the shell completes the command. This technique is useful, but it is sometimes awkward to specify filenames uniquely with their first few characters. In these circumstances it is sometimes convenient to use wildcard characters. Suppose we have three files called FileJim, FileJames and FileJoyce. The first characters of each filename are all rather similar and we want to type

wc FileJim FileJames FileJoyce

Instead of all this typing we could use the wild card character `*'. This can be used to replace any string of characters (except an initial full stop character). So an alternative command would be wc * which would pass the names of all the files in the current directory to wc. However this would produce undesirable results if there were other files apart from FileJim, FileJames and FileJoyce in the current directory. Alternatively:

wc File*

would only use files whose names began `File.' The character `?' is also a wild card, but it can only represent a single character. For example:

rm F*J????

will remove FileJames and FileJoyce because they both have a F followed by any other characters, then J followed by four other characters. The file FverysillylongfilenameJ1234 would also be deleted.


next up previous contents
Next: Redirection and Pipes Up: Shell Commands Previous: The Command History &
© Cambridge University Engineering Dept
Information provided by Tim Love
2005-08-22