Linux shell renders data

Source: Internet
Author: User

    • Input/Output

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

    • redirect Input in script

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

    • Log Messages

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.