pipe 命令用法
By far, the most useful and powerful thing youcan do with I/O redirection is to connect multiplecommands together with what are calledpipes. With pipes, the standard output ofone command is fed into the standard input ofanother. Here is my absolute favorite:
[me@linuxbox me]$ ls -l | less
In this example, the output of the ls command is fed into less. By using this"|less" trick, you can make any command havescrolling output. I use this technique all thetime.
By connecting commands together, you canacomplish amazing feats. Here are some examplesyou'll want to try:
Command | What it does |
---|---|
ls -lt | head |
Displays the 10 newest files in thecurrent directory. |
du | sort-nr |
Displays a list of directories and howmuch space they consume, sorted from thelargest to the smallest. |
Displays the total number of files in thecurrent working directory and all of itssubdirectories. |