Pipeing linux commands and their output
2009-12-08
199 words
1 min read
As a system administrator, I always worry about certain things, like who's doing what, what processes are running, what the network traffic looks like, etc. One day I decided to create a simple alias that would combine all the commands I wanted into one big chunk of information. Then I realized that it wouldn't all fit into one screen.
Fortunately I knew how to group all of the commands together, so the "more" command could handle them as one set of input.
First, here's the wrong way to try to page a sequence of four commands:
date; netstat -i; whodo; ps -ef | more
The only command that gets paged properly here is the "ps -ef" command –the rest of them scroll off the screen before you can read them.
Here's the correct way to page four commands so they're all controlled by "more":
(date; netstat -i; whodo; ps -ef) | more
Once you find the commands you want to group together, you can combine them into an alias or shell program. I recommend a shell program for this, because a few "echo" statements sure make it easier to see where one command ends and the next command begins!
Related Articles:
- 2009/11/25 Linux Installation Guide
- 2009/11/22 Some good and nice open source books worth downloading.
- 2009/11/21 5 Sites To Find Free Alternatives To Popular Software
- 2009/11/20 Add current date and time in vim
- 2009/11/19 Multiple search in vim
Authored By Amit Agarwal
Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.