Pipeline and redirection 1 in linux: the idea of pipeline linux is to collect many small programs, each of which has special expertise. The load task is not completed by large software, but by Shell mechanism, combined with many small programs. Only pipelines and redirection 1 in linux are transmitted between processes through www.2cto.com: the idea of pipeline linux systems is to gather many small programs, each with special expertise. The load task is not completed by large software, but by Shell mechanism, combined with many small programs. The www.2cto.com signal transmits only one signal value between processes, and the pipeline can transmit a large amount of data between processes. The two ends of the MPs queue must be connected to two processes. the process of writing data to the MPs queue is called the write pipeline process. The process of reading data from the MPs queue is called the read pipeline process. The LINUX pipeline mechanism is a one-way pipeline with a fixed transmission direction. Once the data transmission direction is determined, it cannot be changed. In LINUX, pipelines are treated as files and managed using file management methods. However, the fundamental difference between pipelines and files is that, rather than external storage, pipelines use physical memory to store transmitted data. INUX uses the Pipeline buffer in a circular manner, when the data write buffer reaches the end, it continues to write data from the header. As a special file, the LINUX named pipe is included in the file system. it has the same name as a common file and contains the directory items of the named pipe in the directory tree of the file system, there is a difference between the inode node pipeline and common files on the disk. the named pipe uses the memory buffer to store data instead of the data area of the named disk, use input/output redirection in Linux command line mode. if the input required by the command is not from the keyboard, but from the specified file, this is the input redirection. Similarly, the command output can be written to a specified file instead of displayed on the screen. this is the output redirection. Next let's take a look at the practical application of standard input/output redirection in constructing a Linux command. 1. input redirection and output redirection # wc aa.txt # ls> home.txt the first command sets the file aa.txt as the wccommand input, and calculates the number of lines, words, and characters of aa.txt. The second command saves the lscommand output to a file named home.txt. If the file behind the symbol already exists, the file will be overwritten. 2. use both input and output redirection # iconv-f gb18030-t UTF-8 new-aa.txt at the same time with the input direction (new-aa.txt ). Aa.txt is a gb18030 file, while new-aa.txtis a new file that converts the content of aa.txt into UTF-8 format. Use the pipeline to separate the two commands using the pipeline character "|" provided by Linux. the output of the command on the left of the pipeline operator is used as the input of the command on the right of the pipeline operator. The continuous use of pipelines means that the output of the first command will be used as the input of the second command, and the output of the second command will be used as the input of the third command, and so on. Next let's take a look at how the pipeline gets an application in constructing a Linux command. 1. use the pipeline # rpm-qa | grep licq command to create a pipeline with the pipe character "|. The MPs queue uses rpm-qa command output (including all installed RPM packages in the system) as the grep command input to list RPM packages with licq characters. 4. use the command "|" to create an MPs queue. The MPs queue uses rpm-qa command output (including all installed RPM packages in the system) as the grep command input to list RPM packages with licq characters. 4. use multiple pipelines # cat/etc/passwd | grep/bin/bash | wc-l. This Command uses two pipelines, use the first pipeline to send the output of the cat command (display the content of the passwd file) to the grep command. The grep command finds all rows containing "/bin/bash; the second pipeline sends the grep output to the wc command. the wc command counts the number of rows in the input. The function of this command is to find out how many users in the system use bash. Replace the command with the command in Linux command line mode. when a pair of "'" (top delimiter) is encountered, the command contained in "'" is first executed, then, the output result is substituted into the command line as a parameter, which is replaced by the command. It is similar to the redirection function of input and output, but the difference is that the command is replaced with the output of one command as the parameter of another command. Next we will look at its practical application. Www.2cto.com 2. replace # kill '/sbin/pidof smbd' with the command to kill all sshd processes. Here, the pidof command is used to give the process number, because kill operates on the process number. Both of them are replaced by commands, implementing the function of killing all sshd processes with only one command. After understanding and familiarizing yourself with the previous skills, it is a high skill to apply them comprehensively. At the same time, some commonly used and complex Linux commands must be mastered. Some basic and important commands frequently used in constructing Linux commands include grep, tr, sed, awk, find, cat, and echo. Here are some examples of comprehensive applications. 1. # man ls | col-B> ls.man.txt this command uses both output redirection and pipelines to convert ls help information into a text file that can be directly read. Www.2cto.com 2. # kill-9 'PS-ef | grep smbd | tr-s' | awk-f''' {print $2 }'' the same, however, it does not rely on pidof commands. it uses commands in most Unix-type systems and is suitable for more system environments. But it looks more complicated. it uses three pipelines and one command replacement, and grep, tr, and awk commands related to character operations. From the previous introduction, we can see that through the combination of several techniques, Linux commands can complete complex functions. In addition, you can organize these commands into a script, add functions such as functions, variables, judgments, and loops, and add some programming ideas, which is a Shell script with more powerful functions. Redirection: In linux, if you want to save the command output result to a file or use the file content as the command parameter, you need to use redirection. Redirection does not use the standard input port, standard output port, or standard error port of the system. Redirection does not use standard inbound and outbound ports, standard output ports, or standard error ports. Instead, it is re-specified. There are five redirection methods: output redirection, input redirection, error redirection, append redirection, and both output and error redirection. 1: output redirection. Output redirection: saves the output of a command to a file. if the same file exists, it overwrites the content in the source file. The command syntax of www.2cto.com is as follows: command> use output redirection to save/boot contents to/root/abcls/boot>/root/abccat/root/abc use echo command and output redirection to create a text file/ the content of root/mm is hello # echo hello>/root/mm # cat/root/mmhello 2: enter redirection. Enter redirection. the command syntax is as follows; command <file uses input redirection to input the file/root/mm content as the input so that cat commands can be executed # cat </root/mmhello3: append redirection, add the output of a command to an existing file. the command syntax is as follows:> File # echo aaa>/root/a # echo bbb>/root/a # cat /root/aaaabbb
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service