Linux Basic Commands-redirect

Source: Internet
Author: User

the direction of the arrows is the flow of data

Number Description: 0 for standard input, 1 for standard correct output, and 2 for standard error output.

The 2&1> or 2&1>> indicates that the standard correct output is the same as the standard error output. such as: Cho ' I am studying ' 2&1>>/data/boy

< or 0<: Enter the redirect and enter the following items into the previous folder. such as:/data/boy < I am studying

<< or 0<<: Append input redirection, followed by a string, indicating "input end", or "ctrl+d" to end. such as:/data/boy << I am studying

> or 1>: Output redirection, the output of the front to the back of the folder, will clear the original contents of the folder. such as: I am studying >/data/boy

> > or 1>>: Append output redirection, append the front to the end of the folder, does not clear the original contents of the folder. such as: I am studying >>/data/boy


2>: Error output redirection, the previous command execution error message output to the following folder, will clear the original contents of the folder. such as: Cho ' I am studying ' 2>/data/boy will use the command error output to/data/boy.

2>>: Error Append output redirect, append the error message of the previous command execution to the end of the folder, does not clear the original contents of the folder. For example, Cho ' I am studying ' 2>>/data/boy will append the command to the/data/boy with an error.

Ii. use of individual commands

Xargs: Gets content creation and execution commands from standard input. xargs-n [number] represents the number of n groups. such as: Xargs-n 3 </data/boy

Rm-f r [file or directory] Delete file or directory F Force mandatory r recursive recursive delete directory careful use, very dangerous, must first backup before deleting!!!

Find-type [F (file), D (directory), C (character), B (Block), S (socket)] Find by Type

find-name [file name, directory name] Search by name


Sed stream Editor, to achieve the deletion of the text and replace the search.

Sed-i S#old#new#g/data/boy replaces the old in/data/boy with new, s means find substitution, replaces another character with one character, represents a global substitution for the current row with the G Union, #表示分隔符, or it can be used/@ Replace.

SED -I modify file contents

sed -e allows multiple modifications.

Sed-n cancels the default output, such as: Sed-n ' 20,30p '/data/boy displays 20 to 30 rows of/data/boy.

Sed-p Printing,


awk filters the output, which is a processing language, and NR represents the line number. For example, awk ' nr>19&&nr<31 '/data/boy displays 20 to 30 lines of/data/boy.


Head/data/boy Displays the first 10 lines of the file by default

Head-n/data/boy Displays the first n rows of the file by default

Tail/data/boy displays the following 10 lines of the file by default

Tail-n/data/boy Displays the following n rows of the file by default


Linux Basic Commands-redirect

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.