Flowcontrol and Redirects Flashcards
(38 cards)
What are environmental
variables?
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.
What does the PATH environmental variable contain?
Contains a list of search paths for programs
What does the HOME environmental variable contain?
Contains the path to the user’s home directory
What does the USER environmental variable contain?
Contains the current user name
How can the content of a variable be listed?
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.
What is a File Descriptor?
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.
Why can you refer to the three standard streams with a file descriptor?
On Unix (and Linux), everything is a file or represented as a file. The same is true for the three standard streams.
What are the three standard streams?
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.
What is Standard Input?
Standard Input is where the program receives its inputs from. In the case of a command line application, this can be the keyboard.
What is Standard Output?
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.
What is Standard Error?
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.
What for do you need Redirectors?
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 can you redirect a file?
< file Redirect STDIN to read from file
> file Redirect STDOUT to write to file
» file Redirect STOUT to append to file
What does the command “2> file” do?
Redirect STDERR to write to file
What does the command “2» file” do?
Redirect STDERR to append to file
What does the command “2>&1” do?
Redirect STDERR to STDOUT
What does the command “> file 2>&1” do?
Redirect STDOUT to file and STDERR to STDOUT (=file)
What is included by the saying “on Unix/Linux, everything is treated as a file”?
This includes all devices on your sytem, like harddisks, sound cards, scanners, printers or even the USB port.
What is the special file “/dev/null” needed for?
Is necessary for sending output to the nirvana
What is the special file “/dev/zero” needed for?
Is a special file that always reports NULL
What is the special file “/dev/random” needed for?
Reports random characters
What is the special file “/dev/urandom” needed for?
Reports random characters, but is less secure than /dev/random
What does “cat” do on Linux?
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.
What can the | Pipe character do?
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.