"Linux_ Notes" Linux_io redirect, pipeline

Source: Internet
Author: User

Learning resources from: www.magedu.com

Mistakes are unavoidable in the learning process, and if found, they are also pointed out by the great gods.

Some of the sample operations are related to historical operations, and if the previous example operation has not been performed, there may be some examples of operations that cannot be performed. Examples are for informational purposes only. (The exercises are in the appendix)


Computer composition:


The five main components of a computer:
Arithmetic, controller: CPU
Memory: RAM
Input device/Output device
Bus:
Address bus: Memory addressing
Data bus: Transferring data
Control Summary: Control instructions

Register: CPU Ephemeral memory

I/O devices:
Input device: Source of data, mouse keyboard ...
Output device
System Settings
Default output device: Standard output, STDOUT (device name), 1 (descriptor)
Default input device: standard input, STDIN, 0
Standard error Output: STDERR, 2

Standard input: Keyboard
Standard output and Error output: Display

I/O redirection:Change the data output (input) source

Output redirection:
Overwrite output (the original content will be overwritten)
>>: Append output (retains original content)
Example:
Ls/var
Ls/var >/tmp/var.out--output to Var.out (overlay)
Cat/tmp/var.out
Cat/etc/fstab
Cat/etc/fstab >/tmp/var.out--output to Var.out (overlay)
Cat/tmp/var.out
Ls/var
Ls/var >>/tmp/var.out---output to Var.out (append)
Cat/tmp/var.out

SET-C: Prohibit overwrite redirection for already existing files;
Force overwrite output, use >|
Set +c: Turn off the above features
Example:
Set-c
LS/USR >/tmp/var.out--Prohibited coverage
Set +c
LS/USR >/tmp/var.out--Allow coverage
Cat/tmp/var.out
Set-c
LS/USR >| /tmp/var.out--forced override
Set +c

REDIRECT error output:
2&gt: Redirect Error output
2>>: Append mode output
Example:
Ls/varr >/tmp/var2.out--error message output to display
Ls/varr 2>/tmp/var2.out--error message output to Var2.out
Cat/tmp/var2.out
Ls/var 2>/tmp/var2.out--Output either on the monitor
Ls/var >/tmp/var3.out 2>/tmp/err.out
--redirect standard output and error output

&>: Redirect standard output or error output to the same file
Example:
LS/VAR6 &>/tmp/var5.out (var6 not present)
Cat/tmp/var5.out
Ls/var &>/tmp/var5.out
Cat/tmp/var5.out

Enter redirection:
<: Input redirection
<<:here document (Generate documents here)
Example:
Cat
Abc
Ctr+c (Exit)
Cat </etc/fstab
Tr ' A-Z ' A-Z
Abc
Ctr+c (Exit)
Tr ' A-Z ' A-Z '/etc/fstab--cannot be executed
Tr ' A-Z ' A-Z ' </etc/fstab--input redirection

Cat << End (Terminator)
The first line
The second line.
END (Exit)
Cat >>/tmp/myfile.txt << EOF
The first Linde
The second line.
Eof
cat/tmp/myfile.txt--input text is stored in the document

Pipeline: The output of the previous command, as input to the latter command
Command 1 | Command 2 | Command 3 | ...
Example:
echo "Hello, World."
echo "Hello, world," | Tr ' A-Z ' A-Z
Cut-d:-f1/etc/passwd | Sort
Cut-d:-f3/etc/passwd | Sort-n
Cut-d:-f1/etc/passwd | Sort | Tr ' A-Z ' A-Z
Show only the number of lines in the file does not show anything else:
Wc-l/etc/passwd--before using pipe
Wc-l/etc/passwd | Cut-d '-f1


Tee: Read data from standard input, output to standard output and save to file
Example:
echo "Hello,world." | Tee/tmp/hello.out
Cat/tmp/hello.out




This article from "Not Daze" blog, please make sure to keep this source http://tobeys.blog.51cto.com/10620284/1688234

"Linux_ Notes" Linux_io redirect, pipeline

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.