Complete Idiot's Guide to Linux:Putting the Shell to Work
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg) {
var end = document.cookie.indexOf (";", j);
if (end == -1)
end = document.cookie.length;
return unescape(document.cookie.substring(j, end));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
var m1='';
var gifstr=GetCookie("UsrType");
if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; }
document.write(m1+m2+m3);
Keyword
Title
Author
ISBN
Publisher
Imprint
Brief
Full
Advanced Search
Search Tips
Please Select
-----------
Components
Content Mgt
Certification
Databases
Enterprise Mgt
Fun/Games
Groupware
Hardware
IBM Redbooks
Intranet Dev
Middleware
Multimedia
Networks
OS
Prod Apps
Programming
Security
UI
Web Services
Webmaster
Y2K
-----------
New Titles
-----------
Free Archive
To access the contents, click the chapter and section titles.
Complete Idiot's Guide to Linux
(Publisher: Macmillan Computer Publishing)
Author(s): Manuel Ricart
ISBN: 078971826x
Publication Date: 12/22/98
function isIE4()
{
return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') );
}
function bookMarkit()
{
var url="../../../../../www.itknowledge.com/PSUser/EWBookMarks.html@url="+window.location+"&isbn=0";
parent.location.href=url;
//var win = window.open(url,"myitk");
//if(!isIE4())
// win.focus();
}
Search this book:
Previous
Table of Contents
Next
STDERR
The standard error stream, or STDERR, is where error messages are sent. As you enter more complex commands on a shell, youll probably want to have diagnostic or warning messages sent to a log file. Redirecting error messages to a new file is especially useful if you are debugging a shell script.
Redirecting Errors
By default, both STDERR and STDOUT point to your console so you can see diagnostic messages. When you redirect STDOUT, STDERR still points to your console, and any errors are still printed there. To redirect errors, you need to specify a file number.
The input, output, and error streams have assigned file numbers in the shell: STDOUT is 0, STDIN is 1, and STDERR is 2. You can combine the file number and the redirection operator. To redirect errors to a different place, you specify the redirection like this:
command > outputfile 2> errorfile
Messages printed to the standard error stream, STDERR, will go to errorfile, and standard output to STDOUT will redirect outputfile.
For example, lets say you wanted to create a list of all the files on your system. Depending on your user id, you might not have permission to go into some directories. The following command line will redirect permission access errors to a different file while capturing good output in a separate file:
ls -R / > filelist.txt 2> error.txt
Command Groups and Redirection
If you wanted to redirect the output of multiple commands, it would seem reasonable to think that you could use a command like this:
pwd; cd ..; pwd; ls -l > /tmp/listing
However, that command line only redirects the output of the last command. To redirect output for all of the commands, you need to create a command group and redirect standard output for the entire group instead:
(pwd; cd ..; pwd; ls -l) > /tmp/listing
This places the output of each program in succession into the /tmp/listing file.
Pipes: One Programs Output Is Anothers Input
The true power of shells shines when the output from one program becomes the input of another
whose output then becomes the input of yet another, and so on. You can interconnect the input and output of a number of programs in a cascade of useful information. At this point, you might be envisioning a scheme by which you use a series of input and output redirection commands, passing information through a temporary file.
But in a more direct fashion, you can interconnect programs with pipes. Pipes are very useful: They allow you to use the output stream of one program as the input stream of another without the need for temporary files.
For example, if you want a list of all users currently logged into the system, you can use the who command. The who command displays information about each active user, one user per line. If you merely want to know how many users are on the system, but dont need all of the extra information who provides, you need to resort to some trickery. UNIX has a command called wc that counts the number of words, lines and characters that a file contains. Knowing that who outputs information about one user per line, you quickly realize that youd like wc to count the number of lines who displays. You can accomplish this by connecting who and wc together with a pipe:
[alberto@digital alberto]$ who | wc
-l
1
As you can see, the who and wc commands can be piped by connecting them with a vertical bar (|). You can tie together as many programs as you want. However, given our limited command vocabulary, there isnt much we can do yet.
Check This Out: Throwing unwanted output awaySometimes you dont want to see the output from a program on your display, but you also dont want to send it to a file. Maybe you just dont want it at all. For example, when listing all of the files in your system:
ls -R / > filelist.txt >
error.txt
You know that this command sends a list of all the files in your computer to filelist.txt, and the access errors it encounters to error.txt. What if you only want to save or know about the errors? Is there any way to throw the long list of files away as the command runs?
UNIX computers all have a special file in the /dev directory called /dev/null, also commonly referred to as the bit-bucket. Any data sent to /dev/null in a stream is thrown away instantly. To throw away the list of files and just keep the errors, youd type:
ls R / > /dev/null 2>
error.txt
The errors will still be saved in error.txt, but now you dont have to deal with the long list of files.
One common use of pipes is in conjunction with the ls command. If you list a directory that contains many files, such as the /dev directory, the output will scroll past your screen more quickly than you can see it. What do you think the solution is?
If your thought is to make a pipe between ls and a page such as less, you got it! The command you would use to list the /dex directory is this:
ls -l /dev | less
Previous
Table of Contents
Next
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.
Wyszukiwarka
Podobne podstrony:
156 158156 158 dkd742x4orxqog3urgpmrbkeh3feown54evm7ja156 158156 158 (2)151 156 7mp43uhlml3v6grqw4usdl6usks7pprhrkvmq2ipage 158156 ctytREADME (158)więcej podobnych podstron