MPs queue
Main concepts
1. The so-called UNIX "pipeline" can be used to connect a standard output stream of a process with the standard input stream of another process.
2. Many UNIX commands are designed as filters to read the input from the standard input and transmit the output to the standard output.
3. bash uses "|" to create an MPs queue between two commands.
The output of a process can be redirected to a place outside the terminal display, or the process can read the input from a place outside the terminal keyboard. (In short, the input of a process can be neither from the keyboard nor from the display)
One of the most common and advantageous redirection modes is to combine the two. In this situation, a command output (standard output) the pipeline is directly transferred to another command input (standard input), which forms the so-called pipeline for Linux (and UNIX ).
When two commands are connected using pipelines, the standard output stream of the first process is directly connected to the standard input sequence of the second process.
All processes connected to the MPs queue are called process groups)
Pipeline: use the output of the previous command as the input of the next command.
Command 1 | Command 2 | Command 3 | ···
Retrieve the usernames in passwd and sort them.
[[Email protected] tmp] # cut-d:-f1/etc/passwd | sort
Obtain and sort the UID in passwd.
[[Email protected] tmp] # cut-d:-f3/etc/passwd | sort-n
Extract the usernames in passwd, sort them, and convert them into uppercase letters.
[[Email protected] tmp] # cut-d:-f1/etc/passwd | sort | tr 'A-z'' a-Z'
[Tee]
Tee-read from standard input and write to standard output and files
Reads data from standard input and sends it to standard output and files.
That is, a copy of the screen output is saved to a file.
[[Email protected] tmp] # echo "Hello Red Squirrel" | tee/tmp/hello. outHello Red Squirrel [[email protected] tmp] # cat hello. out Hello Red Squirrel
Wc]
Wc-print newline, word, and byte counts for each file
Only the number of lines in the file is displayed. Other information cannot be displayed:
[[Email protected] tmp] # wc-l/etc/passwd | cut-d ''-f133
[Note: There is a space in the middle of the ''of cut-d]
Question:
1. Count the number of files in the/usr/bin directory
[[Email protected] tmp] # ls/usr/bin/| wc-l1434
2. Retrieve the shells of all users on the current system. Each shell must be displayed only once and displayed in order.
[[Email protected] tmp] # cut-d: -f7/etc/passwd | sort-u/bin/bash/bin/sync/sbin/halt/sbin/nologin/sbin/shutdown
3. Thinking: how to display each content type in the/var/log directory?
[[Email protected] tmp] # file/var/log /*
4. Retrieve the 5th rows in the/etc/inittab file.
[[Email protected] tmp] # head-5/etc/inittab | tail-1 # System initialization is started by/etc/init/rcS. conf
5. Retrieve the username and shell of the last 9th users in the/etc/passwd file, display them on the screen, and save them to the/tmp/users file.
[[Email protected] tmp] # tail-9/etc/passwd | head-1 | cut-d:-f1, 7 | tee/tmp/usershaldaemon:/sbin/nologin
6. Display all files starting with pa in the/etc directory and count the number of files.
[[Email protected] tmp] # ls-d/etc/pa * | wc-l4
7. If you do not use a text editor, add a line of alias cls = clear content to the. bashrc file of the current user.
[[Email protected] tmp] # echo "alias cls = clear" >> ~ /. Bashrc
This article from "day up" blog, please be sure to keep this source http://liyasong.blog.51cto.com/3096629/1573826
RHEL-user base-pipeline