Beginner Linux Standard I/O and pipelines

Source: Internet
Author: User

standard inputs and outputs

The program is made up of instruction + data
There are three types of data flow in the program:

Input data flow: <– standard input (stdin), usually the default is the keyboard
Output data stream:–> standard output (stdout), general default to terminal window
Error output stream:–> standard error (STDERR), general default to terminal window

Standard input: 0
Standard output: 1
Error Output: 2

I/O redirection: Changing the default location

Output redirection : redirect standard output (stdout) and standard error (STDERR) to the specified location

Format: command action symbol file name

Supported Operation symbols:
>: Redirect the standard output (stdout) to a file, overwriting the original file contents
>>: Redirect standard output (stdout) to file, append content based on original content

Description : Above is to say ll show the results output redirected to the file, when using >, file files are overwritten, when using >>, the original file and the redirected content are displayed, is the Append content

2>: Redirect the standard error (STDERR) to the file, overwriting the original content
2>>: Redirect standard error (stderr) to file, append content based on original content

Description : The error results of the command execution are displayed in the file files, when using 2>, overwriting the original file output, when using 2>>, the original file content and standard errors are displayed, is the Append content

&>: Redirects all output to a file, regardless of the error output to the specified location, overwriting the output
&>>: Redirect all output to a file, regardless of the error output to the specified location, append output

Note : When using &> or &>>, when executing LL, is the standard output, LLS is the standard error, but no matter which output is redirected to the file files, 2>&1 and &> &>> the same, 2>&1 is used in the old version, to be used at the end, only effect.

Command >/path/toshmefile 2>&1
Command>>/path/to/somefile 2>&1
Understand: A and B, the output of A to B, if yes, the normal output to B, if the error, the content or output on B

Set-c: Prohibits overwriting existing files, but can append mandatory overrides:
Set +c: Allow overwrite

Merge standard output from multiple programs
(command; command) >file

Description : Redirects the standard outputs of ll and echo shells to the file files, which can only be used for standard output,
Standard error cannot be used

TR: converting and deleting characters

TR [option]: SET1 [set2]==>[] not required

Options:
-C: Take the complement of the character ==> replace all characters that are not part of the first character set
-D: Delete all characters belonging to the first character set
-S: Represents a character that repeats repeatedly in a single character
-T: Converts the character of the first character set to the corresponding word in the second character set

Pipe Use symbols | To connect commands
Command1 |command2 |command3 ...
1. Send the standard output of command 1 to command 2, as standard input for command 2, and the standard output of command 2 to Command3 as standard input for command3 ....
2. Standard errors cannot be forwarded by pipeline by default, but can be implemented using 2>&1 or |&
3. The last command executes in the child shell process of the current shell process
4. Multiple tools can be combined

Tee command:

Command1 |tee FileName | Command2
Save the standard output of the Command1 in a file, and then pipe the input to the Command2

Characteristics:

1. Save different stages of output
2. Troubleshooting Complex Pipelines
3. Simultaneously view and record the output

Practice

1./root/the list of files, displaying them as a line, separated by a space between the filenamesls/root/|tr ' \ n '2. Calculate 1+2+3+. The sum of +99+100echo {1..100}|tr ' + ' |BC3. Display the path variable in a separate row for each directoryecho $PATH |tr ":" \ n "4. Replace 0-9 of the specified files into A-jcat/etc/issue | tr ' 0-9 ' a-j '5. Display each word in the file/etc/centos-release (composed of letters) on a separate line with no blank linescat/etc/centos-release | tr "" \ n "

Beginner Linux Standard I/O and pipelines

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.