Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of pipes and named pipes in Linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Xiaobian to share with you what is the use of pipes and named pipes in Linux, I believe most people still do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

In Linux, pipe lets you send the output of one command to another. Pipelines, as their name suggests, redirect standard outputs, inputs, and errors from one process to another for further processing.

The syntax for the Pipe (or Unnamed Pipe) command is to place a line between two commands| Character:

Command-1 | Command-2 | ...| Command-N

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

In the example above, contents.txt contains a list of all files in a particular directory--specifically, the output of the ls -al command. We first grep the file name from contents.txt using the "file" keyword through the pipeline (as shown), so the output of the cat command is provided as input to the grep command. Next, we add a pipe to execute awk, which displays column 9 in the filtered output of grep. We can also count the number of rows in contents.txt using wc -l.

Named pipes can continue to be used as long as the system is up and running or until it is deleted. It is a special file that follows FIFO (first in, first out) mechanism. It can be used just like a regular file. That is, you can write to it, read from it, and turn it on or off. To create a named pipe, the command is:

mkfifo

This creates a named pipe file that can even be used in multiple shell sessions.

Another way to create FIFO named pipes is to use this command:

mknod p

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report