Output
Standard File Descriptors
Standard File Descriptors.
Name | Number | Description |
---|---|---|
STDIN | 0 | Standard Input |
STDOUT | 1 | Standard Output |
STDERR | 2 | Standard Error |
Standard Input
The cat
command reads content from the standard input by default. If you run cat
without specifying a filename, it will wait for user input.
Redirection is done using <
.
Standard Output
The default is the terminal or screen.
Redirection is done using >
or 1>
.
Standard Error
The default is the terminal or screen.
Redirection is done using 2>
.
Using &>
can redirect both standard output and standard error output simultaneously.
EXEC Command
Using in Command Line
The Shell process will be replaced by the new command’s process, and after execution, it will not return to the original Shell.
Using in Script
The script process will be replaced by the date
command, and echo
will not be executed.
File Descriptor Redirection
When modifying file descriptors, it will not replace the current process, but will affect the input/output of subsequent commands.
Closing File Descriptors
Redirecting to &-
will close it. After closing, no more data can be written.
/dev/null
The null device, a bit bucket.
Redirecting both standard output and standard error to the null device.
MKTEMP Command
Creates a temporary file based on a filename template.
The command will replace the X with random characters, and the template must have at least 6 X’s.
Creating Files
Files created by this command only have permissions for the Owner.
Creating Directories
Using the /tmp Directory
Using the -t
option will create files in the /tmp directory.
TEE Command
Simultaneously redirects data to standard output and a file.
The same data is on both the screen and in the file.