Raspberry Pi_Eng_10.8.3 | (pipe) Command


Published Book on Amazon


All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2


출판된 한글판 도서


최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상)
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하)


Original Book Contents


10.8.3  | (pipe) Command

 

In Linux, there is a way to use the output from the execution of one command as input to another command, which is "|" (pipe) command. The word "pipe" here means that all incoming input to the pipe is not removed or sent elsewhere, but is passed to the exit as it is entered without loss of content.

Normally, when a command is executed, it receives input data from an explicitly specified file or input device, processes it in the manner specified by the command, and sends the result to the output.

 


 

 

When you use the pipe function, it sends the result of the previous command to the input of the next command instead of sending it to the normal output such as displaying it on the screen.

 

 


 

In order to use this command, the two commands are sequentially arranged and processed in the following format.

 

[Command Format]

send-command   |   receive-command

 

[Command Overview]

   The result of the previous command is used as the input of the next command.

   User privilege          -- Normal user.

 

[Detail Description]

   None

 

[Used Example]

Here, we wll use the example to retrieve the contents of a large file. First, let's look at the file's data with the "cat" command.

 

pi@raspberrypi ~/ $ cat ./Downloads/debian-reference.en.txt

 

Then, the file has a lot of data, and thus the screen appears as follows. The file data is displayed on the screen from the beginning and continues to proceed until the final contents are displayed and then stopped. In this case, it is not easy to view the beginning of the contents or inquire contents from the beginning.

 


 

This time, we will connect this command with the "less" command.

 

pi@raspberrypi ~/ $ cat ./Downloads/debian-reference.en.txt | less

 

Then, the following screen is displayed, where users can navigate foreward/backward through the data in a way that is generally available in the "less" command.

 


 

This means that the output of the "cat" command can be used as an input to the "less" command, and the basic functions of the "less" command can be used for it.