Running Linux, 5th Edition - Matthias Kalle Dalheimer [79]
$ gcc invinitjig.c 2>error-msg >/dev/null
So now you should be able to isolate exactly the output you want.
In case you've wondered whether the less-than sign (<) means anything to the shell: yes, it does. It causes commands to take their input from a file. But most commands allow you to specify input files on their command lines anyway, so this "input redirection" is rarely necessary.
Sometimes you want one utility to operate on the output of another utility. For instance, you can use the sort command to put the output of other commands into a more useful order. A crude way to do this would be to save output from one command in a file and then run sort on it. For instance:
$ du
> du_output
$ sort -nr du_output
Unix provides a much more succinct and efficient way to do this using a pipe. Just place a vertical bar between the first and second commands:
$ du | sort -nr
The shell sends all the output from the du program to the sort program.
In the previous example, du stands for "disk usage" and shows how many blocks each file occupies under the current directory. Normally, its output is in a somewhat random order:
$ du
10 ./zoneinfo/Australia
13 ./zoneinfo/US
9 ./zoneinfo/Canada
4 ./zoneinfo/Mexico
5 ./zoneinfo/Brazil
3 ./zoneinfo/Chile
20 ./zoneinfo/SystemV
118 ./zoneinfo
298 ./ghostscript/doc
183 ./ghostscript/examples
3289 ./ghostscript/fonts
.
.
.
So we have decided to run it through sort with the -n and -r options. The -n option means "sort in numerical order" instead of the default ASCII sort, and the -r option means "reverse the usual order" so that the highest number appears first. The result is output that quickly shows you which directories and files hog the most space:
$ du | sort -rn
34368 .
16005 ./emacs
16003 ./emacs/20.4
13326 ./emacs/20.4/lisp
4039 ./ghostscript
3289 ./ghostscript/fonts
.
.
.
Because there are so many files, we had better use a second pipe to send output through the more command (one of the more common uses of pipes):
$ du | sort -rn | more
34368 .
16005 ./emacs
16003 ./emacs/20.4
13326 ./emacs/20.4/lisp
4039 ./ghostscript
3289 ./ghostscript/fonts
.
.
.
An alternative to more could be using the head command here, which only shows the first few lines (10 by default). Of course, if there is a head command, there also needs to be a tail command, which just shows the last few lines.
You may have noticed that when using du alone, the output starts appearing fairly quickly and is then added to as the command finishes more computations, whereas when the output is piped to sort, it will take quite a while (if your hard disk is large and well filled) until the output appears. That is because the sort command needs all the data first in order to be able to sort, and not because the piping would delay things.
What Is a Command?
We've said that Unix offers a huge number of commands and that you can add new ones. This makes it radically different from most operating systems, which contain a strictly limited table of commands. So what are Unix commands, and how are they stored? On Unix, a command is simply a file. For instance, the ls command is a binary file located in the directory bin. So, instead of ls, you could enter the full pathname, also known as the absolute pathname:
$ /bin/ls
This makes Unix very flexible and powerful. To provide a new utility, a system administrator can simply install it in a standard directory where commands are located. There can also be different versions of a command—for instance, you can offer a new version of a utility for testing in one place while leaving the old version in another place, and users can choose the one they want.
Here's a common problem: sometimes you enter a command that you expect to be on the system, but you receive a message such as "Not