Linux beginner-Output input management

Source: Internet
Author: User

1. Output redirection

In Linux, because the user has different permissions, access to certain files or directories will be rejected to form an error output, the output of these errors will also be displayed. Normally the correct output is numbered 1, and the error output is numbered 2. For example, in the ordinary user student access to the "/etc/passwd" file, there will be different output. Output management is needed to redirect the output.

You can use the command ">" "2>" "&>" to redirect the correct, error, and full output. If the input command "Find/etc-name passwd >right", is to redirect the correct output to the right file, the wrong output will be displayed directly.

The input command "Find/etc-name passwd 2>error" is to redirect the wrong output to the error file.

The input command "Find/etc-name passwd &>all" is to redirect all output to the all file.

It is important to note that the ">" redirect will overwrite the original file. If you want to overwrite the original file, you need to change ">" to ">>", for example, enter "Find/etc-name passwd >>right" to redirect the correct input to the right file without overwriting the original file.

2. Pipeline

In order to simplify the order, but also for convenience, sometimes need to use the pipeline, the role of the pipeline is to change the output of the previous command into the input of the pipeline command, such as to see how many files and directories under "/etc", use "ls/etc" and then go to the number which is unrealistic, if using the command "LS/ETC | Wc-l "command, you can count it. This command is through the pipe "|" The input of the previous command "LS/ETC" is re-entered into "Wc-l", and the number of directories and files under "/etc" is counted.

If you need to copy the output to the specified location, you need to use "tee". For example, to copy the statistical results from the above command to the output file, enter the command "LS/ETC | Wc-l | Tee output "can be achieved.

The above introduction is only the basic operation of input and output management, but also need to learn more about the application in the later learning and work.

Linux beginner-Output input management

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.