In the context of programming and operating systems, "STD" stands for "Standard." It is commonly used to refer to standard data streams in Unix or Linux systems.
Standard Data Streams
- Standard Input (STDIN)
- Code: 0
- Description: The default input data stream for commands and programs. By default, STDIN is the keyboard, meaning when a program expects input, it receives it from the keyboard unless redirected from a file or another stream.
- Standard Output (STDOUT)
- Code: 1
- Description: The default output data stream for commands and programs. By default, STDOUT is the screen or terminal. When a program generates output, it is displayed on the screen unless redirected to a file or another device.
- Standard Error (STDERR)
- Code: 2
- Description: The default error data stream for commands and programs. Like STDOUT, by default, STDERR is the screen or terminal. The difference is that STDERR is specifically used for error messages, separating them from normal output (STDOUT).
Redirection Operators
Redirecting Standard Output (>
)
Redirects the standard output of a command to a file. If the file exists, it is overwritten.
ls > filelist.txt
This command saves the output of the ls
command into the file filelist.txt
.
Appending Standard Output (>>
)
Redirects the standard output of a command to a file, appending the output to the end of the file if it already exists.
echo "New line" >> filelist.txt
This command appends "New line" to the end of the file filelist.txt
.
Redirecting Standard Error (2>
)
Redirects the standard error output of a command to a file.
ls non_existent_file 2> errorlog.txt
This command saves the error message generated by attempting to list a non-existent file in errorlog.txt
.