Networking / Beginners

Wildcards

Wildcards are one of the most powerful features of command shells. With wildcards, you can process all the files that match a particular naming pattern with a single command. For example, suppose that you have a folder with 500 files in it, and you want to delete all the files that contain the letters Y2K and end with .doc, which happens to be 50 files. If you try to do this in GNOME, you'll spend ten minutes picking these files out from the list. From a shell, you can delete them all with the single command rm *Y2K*.doc.

You can use two basic wildcard characters. An asterisk (*) stands for any number of characters, including zero, while an exclamation mark (!) stands for just one character. Thus, !Text.doc matches files with names like aText.doc, xText.doc, and 4Text.doc, but not abcText.doc or just Text.doc. However, *Text.doc would match any of the names I mentioned.

You can also use brackets to indicate a range of characters to choose from. For example, report[123] matches the files report1, report2, or report3. You can also specify report[1-5] to match report1, report2, report3, report4, or report5. The wildcard r[aeiou]port matches files named raport, report, riport, roport, or ruport. As you can see, the possibilities are almost endless.

[Previous] [Contents] [Next]