You can easily join commands with command symbols. You can use four symbols: pipe (|), ampersand (&), double ampersand (&&), and double pipe (||).
The | Symbol
The | symbol pipes the output from one command (Command A) to another command (Command B). You place the | symbol between the commands:
Command A | Command B
You often have to filter a command’s output before using it. Thus, you’ll probably use the | symbol often to pipe output to the Find command. The Find command searches a command’s output (or text from an input file) for the string you specify. The Find command displays any line that contains the string and discards all the other lines.
For example, suppose you want to know when the C:\winnt directory was created. As I discussed in "Shell Scripting 101, Lesson 2," the Dir command lists information, including creation date and time, about the subdirectories and files in the specified drive or directory. In this case, you use the command
Dir /ad C:\
The /a switch followed by the letter d specifies that you want to list only directories on the C drive.
You now have the information you want, so you just need to pipe it to the Find command to filter out the information you don’t want. As the command
Dir /ad C:\ | Find /i "winnt"
shows, you use the | symbol to pipe the Dir command’s output to the Find command and specify "winnt" as the string for which to search. You need to enclose the string in quotes. The /i switch after Find makes the search case insensitive. As Figure 1 shows, when you run this command, you receive just the line that contains information about the \winnt directory.