Display on the monitor
Redirect to File
Standard file descriptor
0 STDIN Standard Input
1 STDOUT Standard output
2 STDERR standard error redirect error message when you need to develop a file descriptor Ls-al badfile 2> test11111
Ls-al test test123 2> test11 1> test88 tell error message redirect to test11 Normal message redirection to TEST88
&> will redirect the stderr and stdout output to the same output file, the default is to put the stderr on the front, to facilitate the troubleshooting
- Redirecting output in Scripts
Temporarily redirect each row of output
Run the script two lines are displayed, because normally stderr and stdout are output to the monitor, but using the output redirection will see the difference, as follows:
All commands in a permanent redirect script
The EXEC command can be permanently redirected in the script, as follows
EXEC 1> testout Standard output redirect
EXEC 2> testerror standard error redirection
exec must first define to process the next output
EXEC 0< testfile
- Create your own redirects
Create output File descriptor
EXEC 3>test13out
echo "TTTT" >&3
Output this line to Test13out
REDIRECT File descriptor
EXEC 3>&1 redirects the file descriptor 3 to the location of file descriptor 1
EXEC 1>testout redirecting stdout to a file
EXEC 1>&3 Recovery
Create input file Descriptor
Save standard input to descriptor 6, then specify a file for standard input, and then restore standard input after completion
Creating read-Write file descriptors
Colleague reads and writes the same file
<>
Close File descriptor
The created file descriptor is automatically closed when the shell script exits
When you need to close the script prematurely, you need to manually close the exec 3>&-
List Open File Descriptor lsof command
Block command output, you can redirect the output to the empty file in/dev/null.
Create temporary file/tmp directory default is temporary file, you can use Mktemp to create a unique temporary file
Mktemp testing. XXXXXX must be 6 x this 6 x will produce a random number
Mktemp-t test. XXXXXX will create a temporary file in the/temp directory
mktemp-d test. XXXXXX Creating a temp directory
The tee command is equivalent to a T-pipe, sent to two destinations, one destination is stdout, one is the file name specified by the tee command line, the default is overwrite, if you want to append, you need the-a option
Linux shell renders data