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:

Examples of commands used together with pipes
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.

find . -type f-print |wc-l

Displays the total number of files in thecurrent working directory and all of itssubdirectories.



posted @ 2011-08-07 08:56  bambreeze  阅读(302)  评论(0编辑  收藏  举报