Linux Streams, Redirection and Pipes Flashcards
stdin
Standard input - what command you type into terminal
Numerical value = 0
Numerical value aka File Descriptor, is the number the system applies to it
stdout
Standard output on the screen from a command that was run
Numerical value = 1
Default standard output is to your screen, but it’s possible to redirect the output to many other locations/display types
stderr
providing the incorrect standard input will result in an error. This is called the Standard Error. There are other ways to receive a standard error, like incorrect syntax, etc.
Numerical value = 2
redirecting output
It’s possible to redirect the stdout to a file, for instance.
Command to redirect the output of a command to a file:
ls -la > directoryoutput.txt
”>” will pipe the output into a file called “directoryoutput.txt” and overwrite it’s original content
”»” use this to append the document instead of overwriting it
Hint: Think of the > like a funnel point to where the file will go.
Redirectory ex - It’s also possible to redirect to a command, but it’s less common.
How would you redirect errors from a script to a log file?
Example:
./show.sh 1» good.txt 2» errors.txt
Using “1»” will look at standard output and put them in a good.txt file (appending, not replacing).
Using “2»” will take the standard error and put them in a errors.txt file (appending, not replacing).