Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the Linux pipe command

Shulou Source: shulou.com Published: 2022-06-01 23:57:07 09月10日 Update

This article mainly introduces the relevant knowledge of "how to use the pipeline command of Linux". The editor shows you the operation process through the actual case. The operation method is simple, fast and practical. I hope this article "how to use the pipeline command of Linux" can help you solve the problem.

Pipeline is a communication mechanism between multiple processes. Because the data transmitted by the pipeline is unidirectional, it takes the output (stdout) of each previous process directly as the input (stdin) of the next process.

Pipe command

Command1 | command2 | command3 operator is "|", which can only handle the correct output information sent through the previous instruction, but has no direct processing ability for error information. Then, pass it to the next command as standard input.

Output description of the management command:

The correct output of [instruction 1] is used as the input of [instruction 2] and then the output of [instruction 2] is used as the input of [instruction 3], and the output of [instruction 3] will be displayed directly on the screen.

After passing through the pipeline, the correct output of [instruction 1] and [instruction 2] is not displayed on the screen.

[reminder]:

\ 1. The pipe command only handles the correct output of the previous command, not the error output.

\ 2. The command to the right of the pipe command must be able to receive standard input stream commands.

III. Pipeline application

1. Read out the contents of the logcat.log file and forward it to grep as input through the pipeline

Cat logcat.log | grep-n 'ActivitManager'

# 2. Read out the contents of the logcat.log file, forward it to grep as input through the pipeline, filter the lines containing 'Displayed', and then forward the output as input to the next grep through the pipeline.

Cat logcat.log | grep-n 'Displayed' | grep?

# 3. Read out the contents of the logcat.log and wirelessqa.log files, the wrong contents will be printed on the screen, and the correct ones will be transmitted to grep through the pipeline.

# 4. Read out the contents of the logcat.log and wirelessqa.log files, the contents of the error will be redirected to / dev/null, and the correct ones will be piped to grep

# 5. The readout logcat.log is piped to the ls, and the previously read data is lost because ls does not support standard input.

Reasonable use of pipeline commands can greatly improve work efficiency.

This is the end of the content about "how to use Linux pipe commands". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Pipes commands content output input instructions files processing information screens standards knowledge processes data industries different practical inter one-way one-way Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Information MariaDB Shulou Technology vpn