Flowcontrol and Redirects Flashcards

1
Q

What are environmental

variables?

A

Each process has a defined environment in which it is executed. This environment contains certain variables that affect a process’ behaviour. Every variable contains certain values, which can be modified before calling an application.

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

What does the PATH environmental variable contain?

A

Contains a list of search paths for programs

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

What does the HOME environmental variable contain?

A

Contains the path to the user’s home directory

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

What does the USER environmental variable contain?

A

Contains the current user name

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

How can the content of a variable be listed?

A

Using a single command, the content of a variable can be listed if its name is known. If the name is unknown, all defined variables can be listed. For printing the variable’s content, the name must be prefixed with a $ sign.

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

What is a File Descriptor?

A

A File Descriptor is a low-level reference to a file, used by the kernel to access the file. Usually, it is a simple integer.

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

Why can you refer to the three standard streams with a file descriptor?

A

On Unix (and Linux), everything is a file or represented as a file. The same is true for the three standard streams.

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

What are the three standard streams?

A

Standard Input (stdin) = 0, Standard Output (stdout) = 1 as well as Standard Error (stderr) =2. Each program has at least those three file descriptors, represented by the numbers

These three standard streams allow for basic input/output operations of a program. In Java, you can access these streams as System.in, System.out and System.err.

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

What is Standard Input?

A

Standard Input is where the program receives its inputs from. In the case of a command line application, this can be the keyboard.

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

What is Standard Output?

A

Standard Output, on the other hand, is where the program prints its output to. Usually, this is the display in the case of a command line application.

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

What is Standard Error?

A

Standard Error is where all error messages of a program go to. This can be either configured as a log file or the screen, or both.

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

What for do you need Redirectors?

A

As it is not always desirable or practical to read from the keyboard when you want your inputs defined in a file, these standard streams can be redirected to other sources/destinations. For instance a log file, the printer, another program or the nirvana (/dev/null) if no output is desired.

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

How can you redirect a file?

A

< file Redirect STDIN to read from file
> file Redirect STDOUT to write to file
» file Redirect STOUT to append to file

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

What does the command “2> file” do?

A

Redirect STDERR to write to file

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

What does the command “2» file” do?

A

Redirect STDERR to append to file

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

What does the command “2>&1” do?

A

Redirect STDERR to STDOUT

17
Q

What does the command “> file 2>&1” do?

A

Redirect STDOUT to file and STDERR to STDOUT (=file)

18
Q

What is included by the saying “on Unix/Linux, everything is treated as a file”?

A

This includes all devices on your sytem, like harddisks, sound cards, scanners, printers or even the USB port.

19
Q

What is the special file “/dev/null” needed for?

A

Is necessary for sending output to the nirvana

20
Q

What is the special file “/dev/zero” needed for?

A

Is a special file that always reports NULL

21
Q

What is the special file “/dev/random” needed for?

A

Reports random characters

22
Q

What is the special file “/dev/urandom” needed for?

A

Reports random characters, but is less secure than /dev/random

23
Q

What does “cat” do on Linux?

A

The name derives from “catenate” wich means “concatenate” (appending one thing to another thing).
“cat” is used to read from one or more files and output their content to standard output. Obviously, the output can be redirected to files. Sometimes, the usage of this command is useless if the destination command already supports file names.

24
Q

What can the | Pipe character do?

A

The Pipe character “|” combines stdout and stdin. It accepts the standard output of one command and passes it to the standard input of another command, specified after the pipe. Longer pipes are also possible by adding another “|” and another program. Think of it as a stream of fluid (generated by the first program on its standard output) that passes through all specified commands (which eventually modify the stream) and finally end up on the standard output. The pipe character “|” holds them all together.

25
Q

How and why can you combine cat and pipe?

A

“cat” is used to read the content of a very long file that can’t fit to the screen. The content is then piped to “less”, which displays a nice reading environment.

26
Q

What does grep stand for?

A

Grep is an acronym meaning Globally search for regular expression and print

27
Q

What is grep used for?

A

It is used to search for a text or a special pattern in either standard input or a file.

28
Q

What does the tail command do?

A

The “tail”-command prints, as the name suggests, the last few lines of a file or standard input to its standard output.

29
Q

What does the head command do?

A

Again, the name of the command is nearly self-explanatory. Contrary to the “tail”-command, “head” outputs the first few lines of a file or standard intput.

30
Q

What does sed stand for?

A

Streaming editor

31
Q

How does sed work?

A

It operates on streams, which can bei either standard input/standard output or files. Its main purpose is to search and replace in files, although it could do about everything a graphical editor can perform.

“sed” can take regular expressions for its operations, thus enabling very powerful search/replace operations.

32
Q

What are Regular Expressions?

A

A language for defining patterns for matching operations. RegEx, as they are commonly abbreviated, are mainly used for search/replace operations. The language is very powerful, but longer expressions can become very complex.

33
Q

What matches the following RegEx:

.at

A

. Matches any single character, exactly one occurrence

e.g. matches “cat”, “hat”, “bat”, …

34
Q

What matches the following RegEx:

[hc]at

A

[ ] Matches a single character contained in the brackets

e.g. matches only “cat” and “hat”

35
Q

What matches the following RegEx:

[^b]at

A

[^] Matches a single character NOT contained in the brackets

e.g. matches anything from .at except “bat”

36
Q

What matches the following RegEx:

^[hc]at

A

^ Matches the start of a new line

e.g. matches “cat” and “hat” only at the beginning of a new line

37
Q

What matches the following RegEx:

[hc]at$

A

$ Matches the end of a line

e.g. matches “cat” and “hat” only at the end of a line

38
Q

What matches the following RegEx:

s.*

A
  • Matches the preceding character zero or more times

e. g. matches any string starting with “s”, e.g. “saw” or “seed”