Linux Input/Output redirection

Source: Internet
Author: User

In the Linux operating system, we will have some of these requirements, for example, we need to use the shell to write some automated operations scripts, and need to save the execution of the script to another text, this is called output redirection. Sometimes we send an e-mail message that reads from a specified file requires the use of input redirection.


Standard input (stdin) 0
Standard output (STDOUT) 1
Standard error Output (STDERR) 2

Input redirect
Cat </etc/passwd

Output redirection (overwrites the original content)
Df-h >/tmp/disk

Append output redirection (does not overwrite the original content)
Df-h >> Disk

Error output redirection
CAT/ETC/PASSWD 2> A
CAT/ETC/PASSWD 2>/dev/null

Dual output
Cat/etc/abc > OK 2> NG

Input/Output merge (&)
CAT/ETC/PASSWD &>> All

Special Equipment files
/dev/zero Unlimited 0 Resource equipment
/dev/null Trash Cans

Input Terminator
Cat > B << ok normal exit after encountering OK

Cat > B--->ctrl + d normal end
--->ctrl + c forced end

Piping mechanism (TEE)

The pipeline can give the result of a script or command execution to the process behind the pipeline to continue processing

cat/etc/passwd | Wc-l
41

cat/etc/passwd | grep FTP
Ftp:x:14:50:ftp User:/var/ftp:/sbin/nologin

cat/etc/passwd | Wc-l | TEE-A ABC

Tee saves the results of full execution to abc-a append

This article is from the Cloud computing blog, so be sure to keep this source http://huanghaisky.blog.51cto.com/3064496/1918927

Linux Input/Output 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.