Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use pipe symbols in Linux shell

Shulou Source: shulou.com Published: 2022-05-31 18:24:16 09月13日 Update

This article mainly explains "how to use pipe symbols in Linux shell". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use pipe symbols in Linux shell.

Pipe symbol, is a very powerful function of unix, the symbol is a vertical bar: "|".

Usage: command 1 | command 2 his function is to pass the result of the first command command 1 to command 2 as input to command 2, for example:

$ls-s | sort-nr (please be careful not to copy the $symbol into it)

-s is file size,-n, numeric-sort,-r is reverse, reverse

This command lists the documents in the current directory (including size) and sends the output to the sort command as input, and the sort command sorts the output of ls in descending order.

$ls-s | sort-n

Output in order from small to large.

Of course, you can also carry out many operations, such as the following function is to remove pure numbers, and then sed will replace the vertical bar (here is not a pipe symbol) with a space, and then take out the results to sort, and then select the results to display, do not understand can view sorting and paging.

Cat filename | grep-v'^ [0-9] * $'| sed's / | / / g' | sort-nrk 8-nrk 9 | tail-n + 1 | head-n 10

Thank you for reading, the above is the content of "how to use pipe symbols in Linux shell". After the study of this article, I believe you have a deeper understanding of how to use pipe symbols in Linux shell, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Symbols pipes commands functions results learning sorting output content numbers vertical bars order input powerful from small to big from small to big that is ideas situations documents Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux macOS Shulou Tech Info NVidia vpn