Networking / Beginners

Redirection and piping

Redirection and piping are related techniques. Redirection lets you specify an alternative destination for output that will be displayed by a command or specify an alternative source for input that should be fed into a command. For example, you can save the results of an ipconfig command to /home/ doug/myconfig like this:

$ ipconfig > /home/doug/myconfig

Here, the greater-than sign (>) is used to redirect the command's console output.

If a command accepts input from the keyboard, you can use input redirection to specify a file that contains the input that you want to feed to the command. For example, you can create a text file named lookup.commands with subcommands for a command such as nslookup. Then, you can feed those scripted subcommands to the nslookup command, like this:

$ nslookup < /home/doug/lookup.commands

Piping is a similar technique. It takes the console output from one command and feeds it into the next command as input. One of the most common uses of piping is to send the output of a command that displays a lot of information to the more program, which displays the output one page at a time. For example:

$ ipconfig | more

The vertical bar ( | ) is often called the pipe character because it's the symbol used to indicate piping.

[Previous] [Contents] [Next]