Home > System Tutorial > LINUX > body text

What are pipes and named pipes used for in Linux? One article will help you understand

WBOY
Release: 2024-07-15 18:07:44
Original
371 people have browsed it

Linux 中的管道和命名管道有什么用?一文带你了解

The editor will share with you the uses of pipelines and named pipes in Linux. I believe that most people don’t know much about it, so I share this article for your referencelinux named pipe case, I hope you will After reading this article, I have gained a lot. Let’s find out together!

In Linux, pipe allows you to send the output of one command to another command. Pipes, as their name suggests, can redirect the standard output, input and errors of one process to another process linux named pipe case arm linux for further processing.

The sentence pattern of the "pipeline" (or "unnamed pipeline") command is to add the | character between the two commands:

命名管道文件_linux 命名管道 案例_linux有名管道

Command-1 | Command-2 | ...| Command-N
Copy after login

Here, the pipeline cannot be accessed through another session; it is temporarily created to receive the execution of Command-1 and redirect the standard output. It is deleted after successful execution.

Linux中的管道和命名管道有什么用

In the previous example, contents.txt contained a list of all the files in a specific directory—specifically, the output of the ls-al command. We first grep the file names from contents.txt using the "file" keyword through the pipeline (as shown in the figure), so the output of the cat command is provided as input to the grep command. Next, we add a pipeline to execute the awk command, which displays column 9 of the filtered output of the grep command. We can also estimate the number of lines in contents.txt using wc-l command.

A named pipeline continues to be used as long as the system is up and running or until it is deleted. It is a special file that adheres to the FIFO (first in, first out) mechanism. It can be used like a normal file. That is, you can write to the Linux operations blog, read from it, and then turn it on or off. To create a named pipeline, the command is:

mkfifo 
Copy after login

命名管道文件_linux有名管道_linux 命名管道 案例

This will create a named pipeline file which can even be used across multiple shell sessions.

Another way to create a FIFO named pipe is to use this command:

mknod p 
Copy after login

To redirect the standard output of any command to another command, use the > symbol. To redirect the standard input of any command, use

The above is the detailed content of What are pipes and named pipes used for in Linux? One article will help you understand. For more information, please follow other related articles on the PHP Chinese website!

source:itcool.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!