Week 6: Unix Command I/O and Redirection, Processes and Job Control Flashcards
When a Unix process starts, how many streams are opened?
Three streams:
- Standard Input (stdin): default place from which programs read
- Standard Output (stdout): default place to which programs write
- Standard Error (stderr): default place where errors are reported
What is the default standard input/output/error?
Input: keyboard
Output: display
Error: display
For file redirection, what is the symbol for redirecting standard input?
<
or
0
For file redirection, what is the symbol for redirecting standard output?
>
or
1>
EX: cat file1 file2 > file3
For file redirection, what is the symbol for redirecting standard error?
2>
For file redirection, what do the following do?
cat file1 file2 > file3
cat file1 file2 >| file3
cat file1 file2»_space; file3
cat > file3
cat file1 file2 > file3
– concatenates file1 and file2 into file3
– file3 is created if not there
cat file1 file2 >| file3
– file3 is clobbered if there
cat file1 file2»_space; file3
– warning if file3 is not there
– file3 is appended to if it is there
cat > file3
– file3 is created from whatever user provides from
standard input
What would the format be to redirect standard from a file named myfile:
Standard output to “yourfile” and standard error to “yourerrorfile”?
cat myfile > yourfile 2> yourerrorfile
What does the following do?
cat myfile &> yourfile
If myfile exists, it is copied into yourfile
If myfile does not exist, an error message cat: myfile: No such file or directory is copied into yourfile
What does the following do?
cat myfile > yourfile 2>&1
stdout goes to yourfile and stderr goes to where stdout goes. The same thing as cat myfile &> yourfile
What does tr string1 string2 do?
character n of string1 translated to
character n of string2
What do the following do?
compute[3] > tr aeoiu eoiua file2
compute[4] > tr eoiua aeoiu file2
compute[5] > tr a-z A-Z < file1 > file2
Replace every occurrence of the characters in string1 with those in string2
file1 as input, redirect it to the translation, and place the output in file2
What is /dev/null
A virtual file that is always empty.
Copy a file to here and they disappear
Copy a file from here and get an empty file
Redirect error messages here and they disappear as well
What are tr, grep, wc, and sort examples of?
Filters
Grep, by default, writes the ____ containing the phrase to stdout
LINES
What does the following do?
grep “unix is easy” < myfile1 > myfile2
Write all lines of myfile1 containing phrase unix is easy
to myfile2
What does wc do?
Count the number of chars/words/lines on stdin and write the resulting statistics to stdout
What does the sort filer do?
Sort all the input lines in alphabetical order and write to
the standard output.
What does a “pipe” do in essence?
Connects stdout of one program with stdin of another
What is an alternative way, using pipes, of writing the following?
compute[2] > grep unix < readme.txt > tmp
compute[3] > wc -l < tmp
cat readme.txt | grep unix | wc -l
To include standard error in a pipe, what is the syntax?
command1 |& command2
What will the shell do when given the following command?
readme.txt > grep unix | wc -l
Your shell will go looking for a program named
readme.txt
What does the “tee” command do?
replicate the standard output:
cat readme.txt | tee myfile