06 Redirection Flashcards
What is the function of the “cat” command
Concatenate files
What is the function of the “sort” command
Sort lines of text
What is the function of the “uniq” command
Report (or omit) repeated lines
What is the function of the “grep” command
print lines of text matching a given pattern
What is the function of the “wc” command
Performs a word count; yields newlines, word count, and byte count of a file
What is the function of the “head” command
print ‘n’ lines from the beginning of a file
What is the function of the “tail” command
print the last ‘n’ lines from a file
What is the function of the ‘tee’ command
read from stdin, write to stdout AND to a file
Program output consists of what two types of data?
- Program execution results
2. Status/error messages
Programs send their output to a special file (typically the screen), known as … ?
Standard Output
What is the REDIRECTION operator?
>
What is the APPEND operator?
> >
If standard error has a file descriptor of ‘0’, where does the output go?
A file descriptor of ‘0’ sends error output to standard input
If standard error has a file descriptor of ‘1’, where does the output go?
A file descriptor of ‘0’ sends error output to standard output
If standard error has a file descriptor of ‘2’, where does the output go?
A file descriptor of ‘0’ sends error output to standard error
Assuming you give the command:
“ls -l /bin/usr 2> ls-error.txt”
Describe the output
list the contents of /bin/usr, which does not exist,
take the output that would’ve gone to standard error, and write it out as a new file ls-error.txt
You issue the ‘cat’ command with no arguments. Describe what the system is doing…
Cat is reading from stdin (waiting for keyboard input)
What is a ‘pipeline’
connects stdout to stdin of the next command
What is the difference between ‘>’ and ‘|’ ?
Redirection connects a command to a file
A Pipeline connects the output of one command with the input of the next command.
Describe the output of this command:
ls /bin /usr/bin | sort | less
- Create two directory listings (/bin, /usr/bin), passed to sort
- Sort command yields a single, sorted list; passed to ‘less’ command
- less outputs that single sorted list to screen
Describe the output of the following command:
ls /usr/bin | tee ls.txt | grep zip
- list directory /usr/bin; passed to ‘tee’
- ‘tee’ writes directory listing to ls.txt, passes output to grep
- Grep searches the directory listing for “zip”, writes matched lines to screen