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.
In this tutorial:
- Linux Commands
- Command Shell Basics
- Editing commands
- Wildcards
- Redirection and piping
- Environment variables
- Shell scripts
- Directory and File Handling Commands
- The cd command
- The mkdir command
- The rmdir command
- The ls command
- The cp command
- The rm command
- The mv command
- The touch command
- The cat command
- Commands for Working with Packages and Services
- The rpm command
- Commands for Administering Users
- The usermod command
- The chage command
- The passwd command
- The newusers command
- The groupadd command
- The groupdel command
- Commands for Managing Ownership and Permissions
- The chgrp command
- The chmod command
- Networking Commands
- The ipconfig command
- The netstat command
- The ping command
- The route command
- The traceroute command