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 pipeline command in Linux system

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is about what pipe commands are in the Linux system. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The pipeline command refers to the processing of the correct output information sent through the previous instruction, and there is no direct ability to deal with the error information. It is then passed to the next command as standard input.

Pipe command pipeline is a communication mechanism, which is usually used for inter-process communication (or network communication through socket). It takes the output (stdout) of each previous process directly as the input (stdin) of the next process.

The pipe command uses | as a delimiting symbol, and the pipe command is different from the continuous execution command described above.

Pipe commands can only handle standard output and are ignored for standard error output. Less,more,head,tail... Can accept standard input commands, so they are pipe commands ls,cp,mv will not accept standard input commands, so they are not pipe commands.

The pipeline command must be able to accept the data from the previous command as standard input to continue processing.

The first pipe command $ls-al / etc | less takes the output of ls-al through the pipe as the input of the next command less for easy browsing.

Processing diagram of pipeline command

Select command: cut.grepcut: take a certain part of the information we want from a line of information.

Cut-d 'delimiter'-f field / / used for delimiting character ``cut-c character range`` [parameter description] ``- d: followed by a delimiter, usually used with-f``-f: separate information into segments according to-d -f followed by a number indicates the paragraph in which to take out ``- c: take out the information of the fixed character range in characters 1: the first and sixth fields in the print / etc/passwd file separated by: indicate the user name and home directory [root@izuf6i29flb2df231kt91hz /] # cat etc/passwd respectively. | cut-d':'- f 1Pol 6 root:/root bin:/bin daemon:/sbin adm:/var / adm lp:/var/spool/lpd... Chestnut 2: print the first 10 characters of each line in the / etc/passwd file: [root@izuf6i29flb2df231kt91hz /] # cat / etc/passwd | cut-c 1-10 root:x:0:0 bin:x:1:1: daemon:x:2 adm:x:3:4: lp:x:4:7:l. * ps:cut is difficult when dealing with data with multiple spaces. *

Grep: analyze a line of information, and if there is any information we need, take it out

Grep [- acinv] [--color=auto] 'find string' filename`` [Parameter] ``- a: use binary file to find data as text file``-c: calculate the number of times to find 'find string' ``- I: ignore case differences``-n: output line numbers``-v: reverse selection Display line ``- color=auto: add color to the keyword found and display Chestnut 3: take out the line [root@izuf6i29flb2df231kt91hz /] # cat etc/passwd containing the / etc/passwd file of fanco | grep-n-c 'fanco' 1 [root@izuf6i29flb2df231kt91hz /] # cat etc/passwd | grep-n' fanco' 23:fanco:x:1001:1001::/home/fanco:/bin/bash [root@izuf6i29flb2df231kt91hz /] # cat Etc/passwd | grep-n-v 'fanco' 1:root:x:0:0:root:/root:/bin/bash 2:bin:x:1:1:bin:/bin:/sbin/nologin 3:daemon:x:2:2:daemon:/sbin:/sbin/nologin 4:adm:x:3:4:adm:/var/adm:/sbin/nologin 5:lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin.

Add the-color parameter, it seems to have a color without default.

Sort command: sort,wc,uniqsort

Sort [- fbMnrtuk] [file or stdin] ``[Parameter] `- f: ignore the case difference. For example, An and an are considered to have the same encoding``-b: ignore the first space ``- M: sort by month's name, such as JAN, DEC, etc.``-n: sort by text by default using "pure number") ``- r: reverse sort``-u: uniq In the same data, only one line stands for ``- t: separator The default is to use the [tab] key to separate ``- k: sort by that field. Chestnut 4: sort the accounts of / etc/passwd [root@izuf6i29flb2df231kt91hz /] # cat / etc/passwd | sort adm:x:3:4:adm:/var/adm:/sbin/nologin bin:x:1:1:bin:/bin:/sbin/nologin chrony:x:998:996::/var/lib/chrony:/sbin/nologin. Sort by column 5 of / etc/passwd [root@izuf6i29flb2df231kt91hz /] # cat etc/passwd | sort-t':'- k 3 root:x:0:0:root:/root:/bin/bash fanco:x:1001:1001::/home/fanco:/bin/bash operator:x:11:0:operator:/root:/sbin/nologin bin:x:1:1:bin:/bin:/sbin/nologin games:x:12:100:games:/usr/games : / sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin the sort here is still sorted by text Switch to numerical sort [root@izuf6i29flb2df231kt91hz /] # cat etc/passwd | sort-t':'- k 3-n root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologinuniq

Uniq [- ic] ``[ Parameter] ``- I: ignore case difference``-c: count chestnut 5 accounts that use last to take out historical login information, sort, and remove [root@izuf6i29flb2df231kt91hz /] # last | cut-d'- f 1 | sort | uniq-c 1 7 reboot 19 root 1 wtmpwc

View the number of lines, characters and characters of a file [root@izuf6i29flb2df231kt91hz /] # cat etc/passwd | wc 23 32 997 two-way redirection command: teetee:

A certain piece of information is saved during the processing of the data stream, so that it can be output to both the screen and a file.

Workflow of tee. PNG

Tee [- a] file`` [parameters] ``- a: add data to file by adding data to Lizi 7 query recent user login status and save it to file [root@izuf6i29flb2df231kt91hz /] # last | tee info | cut-d'- f 1 root. [root@izuf6i29flb2df231kt91hz /] # less info root pts/0 112.28.181.159 Sun Jul 1 14:28 still logged in root pts/0 112.28.181.159 Sun Jul 1 14:24-14:27 (00:03) root pts/0 112.28.181.159 Sun Jul 1 13:19-14:24 (01:04) root tty1 Sun Jul 1 12:46 still logged in if the file followed by tee already exists The content will be overwritten, and the-a parameter will accumulate.

Character conversion command: tr,col,join,paste,expandtr: used to delete the text in a message, or to replace the text message

Tr [- ds] set`` [parameter] ``- d: delete the string set1 in the message``-s: replace the duplicate character Chestnut 8 to delete all info files generated in the previous step [root@izuf6i29flb2df231kt91hz /] # cat info root pts/0 112.28.180.86 Thu May 10 18:01-18:12 (00:11) reboot system boot 3.10 .0-693.2.2.e Fri May 11 02:00-16:31 (51mm 14cat info 30) after deletion [root@izuf6i29flb2df231kt91hz /] # cat info | tr-d 'root' ps/0 112.28.180.86 Thu May 10 18:01-18:12 (00:11) eb sysem b 3.10.0-693.2.2.e Fi May 11 02:00-16cat info (51mm 1430) deletion does not only delete consecutive characters Reboot has also been deleted. The root part removes the ^ M symbol left by the dos file $cat / root/passwd | tr-d'\ r'> / root/passwd.linux ^ M can replace col with\ r.

Col [- xb] ``[ Parameter] ``- x: replace the tab key with the equivalent space bar``-b: when there is a backslash (/) in the text, only the last character of the backslash is retained

Chestnut 9 replace ^ I in the image above with the space bar [root@izuf6i29flb2df231kt91hz /] # cat info | col-x | cat-A | more root pts/0 112.28.181.159 Sun Jul 1 14:28 still logged in$col is often used to dump man page as a plain text file

Join: two files have the same data on a line, with the same field in front of it.

Join [- ti12] file1 file2`` [Parameter] ``- t: join separates the data with a space character by default, and compares the data of the first field, if the two files are the same Etc/shadowpaste: directly paste two files and two lines together Separated by [tab] key in the middle

Paste [- d] file1 file2` [parameter] ``- d: can be followed by a delimiter. By default,``-separated by [tab]: if the file part is written as- Chestnut 11 [root@izuf6i29flb2df231kt91hz /] # paste info info2 root pts/0 112.28.181.159 Sun Jul 1 14:28 still logged in root pts/0 112.28.181.159 Sun Jul 1 14:28 still logged in root pts/0 112.28.181.159 Sun Jul 1 14:24-14:27 (00:03) Root pts/0 112.28.181.159 Sun Jul 1 14:24-14:27 (00:03) root pts/0 112.28.181.159 Sun Jul 1 13:19-14:24 (01:04) root pts/0 112.28.181.159 Sun Jul 1 13:19-14 root pts/0 24 (01 root pts/0 04) * expand: turn the tab key into a space bar

Expand [- t] file [parameter] "- t: followed by a number. Generally, a tab can be replaced by 8 spaces, and you can define how many spaces you want to represent.

Chestnut 12 [root@izuf6i29flb2df231kt91hz /] # cat info | expand-3 info root pts/0 112.28.181.159 Sun Jul 1 14:28 still logged in root pts/0 112.28.181.159 Sun Jul 1 14:24-14:27 (00:03) root pts/0 112.28.181.159 Sun Jul 1 13:19-14:24 (01:04) root tty1 Sun Jul 1 12:46 still logged in cutting command: splitsplit: as the name implies Cut a large file into small files according to the file size or the number of lines.

Split [- bl] file prefix`` [Parameter] ``- b: the size of the file you want to cut can be followed by the size of the file you want to cut, and you can add units, for example, bmeme kprim, etc.``-l: cut by the number of lines ``PREFIX: represents the leading character Chestnut $split-b 300K / etc/passwd divides the ls-al output file into a new file [root@izuf6i29flb2df231kt91hz /] # ls-al / | split-l 10-lsrrot [root@izuf6i29flb2df231kt91hz /] # ls b boot dev home info2 lib64 lsrrotaa lsrrotac mnt opt root sbin sys usr bin c etc info lib lost+found lsrrotab media n proc run srv tmp var [root@izuf6i29flb2df231kt91hz /] # cd by 10 lines / [root@izuf6i29flb2df231kt91hz /] # ls b boot dev home info2 lib64 lsrrotaa lsrrotac mnt opt root sbin sys usr bin c etc info lib lost+found lsrrotab media n proc run srv tmp var [root@izuf6i29flb2df231kt91hz /] # wc-l lsrrot* 10 lsrrotaa 10 lsrrotab 9 lsrrotac 29 total Thank you for reading! This is the end of the article on "what is the pipeline command in the Linux system". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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

Development

Wechat

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

12
Report