UNIX System Management: input and output redirection

Source: Internet
Author: User
Keywords UNIX System Management
Tags basic cat change date error error message file mail

To complete this chapter, you can do the following things:

Change the output of the Unix command so that it is output to a file.

Prints the error message generated by the UNIX command to the file.

Change the input of UNIX commands.

Define a filter

Use some basic filters such as Sort,grep and WC.

9.1 Introduction to input and output redirection

The shell provides the ability to redirect the input and output of a command. The output of most commands is output to the terminal screen, such as date,ls,who and so on, many commands are entered from the keyboard, and commands include Mail,write,cat.

Any object in a UNIX system is a file, including a terminal and a keyboard. Output redirection lets you send an output of a command to a file other than a terminal. Input redirection lets you get input from a file other than the keyboard.

Output redirection can be used to capture the output of a command, record it as a log record, or further process it. Input redirection allows you to create a file using an editor and then send the file to a command instead of an interactive input method without editing capabilities (such as mail commands).

This chapter describes input and output redirection, and then introduces some of the UNIX filters. A filter is a special tool that can further process the contents of a file.

9.2 standard input, standard output, and standard error

Each time the system is started, it will automatically create three files, which are called standard input, standard output, standard error.

The shell gets input from the standard input file. This file is opened using the C language descriptor "0", usually pointing to your keyboard. So, when the shell needs input, it must use the keyboard to enter the data.

Some commands, such as Mail,write,cat, are entered from the standard input, in the form of input commands and parameters, carriage returns, and then the command waits for you to provide input for processing. The end sign entered is carriage return and CTRL

The shell writes the output to the standard output file, which is opened using the C language's descriptive symbol "1", usually your terminal. So when the shell produces output, these output data are usually displayed on your screen

Most UNIX commands produce standard output, these commands are date,ls,cat,who and so on.

The shell prints the error message to the standard error file, which is opened using the C language Descriptor "2". As with standard output, standard errors are exported to your terminal. Standard errors can be redirected to output to separate standard error files.

Most Unix system commands produce an error message when improperly invoked. To see an example of a standard error, type: CP then enter. CP usage information is displayed on your screen, which is actually transmitted through standard error streams

Here's how you can change standard input, standard output, default values for standard errors, such as getting input from a file instead of the keyboard, and generating output (and error messages) elsewhere instead of at the terminal.

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.