Monday, 1 April 2013
GROUPING COMMAND IN LINUX
GROUPING COMMAND
- Two ways to group commands:
- Compound:date ; who WC -I
- Command run back-to-back
- All output is sent to a single STDOUT and STDERR
Aggregating Output Redirection:
Suppose you want to maintain a count of the number of users logged on,along with a time/date stamp,in a log file.This could be accomplished with two commands:
[student@tationX ~] $ date >> log-file
[student@tationX ~] $ who / WC -1 >> log-file
This command sequence required that you enter two lines of command,append to log-file twice,and in general,type much more than is necessary.When writing to the terminal,this task can be simplified by combining the command on one line separated by semicolons:
[student@tationX ~] $date; who /WC -1
But if your intent is to redirect standard output,this will not work as expected:
[student@tationX ~] $ (date; who /WC -1) >> log-file
Both commands will run,but only the second one will redirect its output to log-file.
subs-hells
Commands inside parentheses are run in their own instance of bash,called a subshell. The output of all commands run inside a subshell are sent to the subshell's STDOUT and STDERR,making it possible to send multiple programs through the same pipe:
[student@tationX ~]$ (date; who /WC -1) >> log-file
THANK YOU FOR VISITED GURU NETWORK I HOPE LIKE THIS IT ARTICLE
THANK YOU FOR VISITED GURU NETWORK I HOPE LIKE THIS IT ARTICLE
Author: Kuldipsinh
Hi! I am Kuldipsinh,a certified Indian Network Consultant,Pro Blogger,Computer Engineer Software Editor and an addicted Web Developer. Read More →
Related Posts:
COMMAND LINUX
Subscribe to:
Post Comments (Atom)
0 comments: