Linux Basic Concepts-----Linux I/O redirection, piping

Source: Internet
Author: User

Standard input: Keyboard

Standard output: Display

Error Output: Display


FD: File Descriptor: Allows the program to interact with the file, and facilitates the kernel to identify the file, each open file has a descriptor


The program interacts with the file interactively, through the file descriptor, rather than the file name, and the file name is user-friendly separately.


Linux all files, so standard input, standard output has its own file descriptor


Standard input Descriptor: 0

Standard Output Descriptor: 1

Standard error Output Descriptor: 2


To change its default data stream to another device: IO redirection


Output redirection

> Overwrite redirects

>> Chasing heavier orientation


/dev/null Black Hole


For the current shell only

sed-c filename Turn off output redirection: If the output file exists, overwrite is not allowed

Forced Overwrite: >|

sed +c filename Start output redirection function



Also define standard output and standard error redirection to different files


COMMAND >/tmp/aa.txt 2>/tmp/bb.txt


REDIRECT standard input and standard error output to the same file

COMMAND & >/dev/null

COMMAND & >>/dev/null


Input redirect

<

COMMAND </filename

<< Create file here

Cat > FileName << EOF is typically used for production files in scripts

Adasd

Asdasd

EOF End Character


Cat << EOF is typically used to output a large segment of information to the user

Sdfsf

Sdfsdf

EOF End Character


Pipeline | : The output of one command is redirected to another command as a parameter using the

COMMAND | COMMAND |

The last command of the pipeline, executed in the child shell of the current shell


Tee

The multi-channel output is output on the screen, and the output is saved in only one file

cat/etc/passwd | Tee filename

#######################################################

Cat-n filename Display file line number

Head-n fetching n rows of file contents: From the first line to the nth row

Tail-n fetching n rows of file contents: from the last line to the nth row


This article is from the "Hanging Sword" blog, please be sure to keep this source http://sublime.blog.51cto.com/8856101/1439610

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.