Topic 5 - Unix Input-Output Redirection Flashcards

1
Q

During execution of a program, where are the input/output/errors directed to?

A
They're directed from/to:
Standard Output (stdin)
Standard Output (stdout)
Standard Error (stderr)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Where can these outputs be redirected to?

A

Any file or device other than the terminal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the redirect output symbol?

A

>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you redirect output so that it is appended to the end of a file, adding to the end of a file?

A

> >

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Can standard output be redirected independently from standard error?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you redirect in bourne-style shells?

A

standard error = 2>
standard output = 1> or simply >
Can use 2>&1 to re-direct to the same name file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How you append in bourne-style shells?

A

2» instead of 2>
1» instead of 1>
» instead of >

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you redirect in C-style shells?

A

redirected together to a file using “>&”;;
Independently: two files as follows:
( cat file3 file2 > output_file ) “>&”; error_file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you append in C-style shells?

A

> > &; instead of >&;

|&raquo_space; instead of >

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the Redirect Input symbol ?

A

less than sign

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Standard input can also be redirected from the text to be written immediately after the command using the ______.

A

two less than signs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

You have a file named greekfile with the following contents:

 WELCOME TO 
 GeeksforGeeks

How will you uppercase all of the letters?

A

cat greekfile | tr “[a-z]” “[A-Z]”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the command grep do?

A

Global Regular Expression and Print.

searches text files for matching pattern and prints matched patters to standard output.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between wildcards and regex?

A

File name wildcards are interpreted and matched by shells. Regex are interpreted and matched by special utilities.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the wc command do

A

prints the number of lines,w words, and bytes in a file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does the sort command do

A

sort all input lines in alphabetical order. Write the result to the standard output.

17
Q

What does the uniq command do

A

removes duplicated lines from a sorted file, writes the result to the standard output.

18
Q

What is a pipe?

A

Connects standard output of one program to standard input of another. General Form: command1 | command 2

19
Q

Describe the tee command.

A

tee - replicates the standard output like a T connection:
cat read.txt
cat read.text > myfile

cat read.txt | tee myfile

20
Q

what is /dev/null?

A

a virtual file that is always empty - redirecting to here means discard errors