Linux entry record: 16, Linux Multi-command collaboration: Pipeline and redirection

Source: Internet
Author: User
Tags stdin

One, multi-command collaboration

In Linux systems, most commands are simple, with few complex commands, and each command often implements only one or more simple functions. You can implement a complex function by using a combination of commands from different functions.

The return data for almost all commands in Linux is plain text (because each command runs under the CLI), and data in plain text is the input format for most commands, which makes multi-command collaboration possible.

The Linux command line provides a pipeline and redirection mechanism, and multi-command collaboration is done through pipelines and redirects.

Second, the standard flow

For a terminal, it is possible to work with various types of data, int, float, double, char, string, or even a text file, and the terminal attaches more importance to the contents of the data itself, ignoring the type of the data and focusing on their content, abstracting them into a "stream" The concept of (Stream). The data flow is also generally called an I/O stream.

Almost every terminal has the I/O (input and output) of the data stream, generally, stream-based trends and uses have input streams, output streams, error streams, file streams, and so on, and generally, there are 3 default standard streams:

Name Description

Number

(File descriptor)

Default Device
Stdin Standard input stream 0 Keyboard
STDOUT Standard output stream 1 Terminal
STDERR Standard error Liu 2 Terminal

STDIN represents the standard input stream, which is usually the keyboard by default. STDOUT and STDERR, respectively, represent standard output streams and standard error streams, which are typically terminals by default.

Iii. Piping and redirection 1. redirect

Redirection can direct I/O streams (associations) to files rather than to the default terminal. Redirection is typically used to save the output or error information of a command to a specified file.

There are several common operators:

> redirect       stdout to file (overwrite) >> redirect      stdout to file (append) 2> redirect      stderr to file (overwrite) 2>&1    REDIRECT StdErr and stdout to file (overwrite) < redirect       stdin to File

2. Piping

Pipeline operations can implement the output of one command as input to another command. Pipelines are often used to combine different commands to achieve a complex function.

Operator:

|        StdOut a command as a stdin of another command

Linux entry record: 16, Linux Multi-command collaboration: Pipeline and redirection

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.