1.6 Redirection and Piping Flashcards
What is the difference between redirection and piping?
- Redirection occurs to and from files - sending command output to a file or getting command input from a file.
- Piping occurs between commands - connecting the output of one command to the input of another.
When might you choose to redirect the input of a command?
When you wish to take command input from a file rather than the keyboard.
What are the three default file descriptors that Linux uses to classify information for a command?
- Standard input or STDIN, file descriptor 0
- Standard output or STDOUT, file descriptor 1
- Standard error or STDERR, file descriptor 2
How can you overcome the 128 KB shell command size restriction?
You can overcome the 128 KB shell command size restriction by using the xargs command.
What is the default file descriptor if none is specified?
File descriptor 1, standard output.
What are the symbols for redirecting standard intput, standard output, and standard error?
- Standard input - command < filename
- Standard output - command 1> filename
- Standard error - command 2> filename
How do you redirect both standard output and standard error to a file?
command 1> filename 2> &1
How do you connect a file to the standard input of the sort command?
sort < filename
What is redirection?
Redirection directs standard input, output, and error streams from and to locations other than the default.
What is piping?
Piping connects the output stream of one command to the input stream of another command.
What is standard input and what is its file descriptor?
Standard input (stdin) comes from the keyboard. In redirection, 0 represents stdin.
What is standard output and what is its file descriptor?
Standard output (stdout) displays on the monitor. In redirection, 1 represents stdout.
What is standard error and what is its file descriptor?
Standard errors (stderr) display on the monitor. In redirection, 2 represents stderr.
What are the redirection symbols and how do they work?
- Greater-than symbol (>) - redirects output
- Less-than symbol (<) - redirects input
- Double greater-than symbol (>>) - appends output
What does the tee command do?
The tee command reads from standard input and writes to standard output and to files.