Printing

The Commands

lpr
- This command sends a file to the printer. In most cases, only a text file or a post script file can be sent to the printer. On the RCS system, the file you wish to print gets sent to the printer nearest to you (I think). There are several options you can pass to lpr :
-P
Specifies the name of the printer. Ex : lpr -Psagelw filename (``sagelw'' is the name of the printer). This is useful useful when you want to send your printout to a printer other than the default one.
-h
Supresses the printing of the title page (this saves you a nickel each time you print but can also make finding your printout tough if there are many other printouts waiting).

lpq
- You can take a look at the printer queue (the printer queue is just the waiting line of files to be printed out) by typing lpq. The output contains a job number. This is important if you need to remove your file from the print queue.
lprm
- If you know the job number (from the output of the lpq command, you can remove your file from the print queue by typing lprm number where number is the job number.
enscript
- This command converts ascii (ascii is just plain ordinary text - as opposed to a gif which is not plain ordinary text) to post script and sends it to the printer. This is a very good way to make your text files look ``nice''. All the options to lpr seem to work with enscript, but enscript has other options available too :
-2Prints out in two columns.
-rPrints out in landscape format.
-GGaudy format : prints the filename, time and date at the top.

So, for example, enscript -2rGh filename prints the file called filename to the default printer in 2-column landscape format with the date, filename and time at the top. It also does not print the extra title page (-h : the lpr option).

Redirection/Pipes/Filters

The Commands

Almost all communication to and from UNIX is done with input and output. In particular, there are two types of input and output (I/O henceforth): standard input and standard output. Standard input is from the keyboard and startard output is to the screen or monitor. When we talk about ``redirection'' we mean to change where the standard input and stardard output comes from and goes to.
>
- Redirects standard output.
>>
- Redirects stardard output by appending (instead of overwriting).
<
- Redirects standard input.
|
- ``Pipe'' : Turns the standard output of one command to the stardard input of the next command.

Some Exercises

  1. There's a command called who that is similar to finger. Try it and take note of the output.
    who
  2. Notice that in a general sense, you get text on the screen which means that the ``standard output from the who command was sent to the screen''. Now let's redirect that standard output to a file.
    who > junk
  3. Look at the junk file and you should see that the file contains the output from the who command. Now, try to redirect the output of the date command to the same file.
    date > junk
    Your shell (bash) will probably not let you do it because it won't let you ``accidentally'' clobber the existing file. You would first have to remove the file junk and then reexecute the command (but don't do it now).
  4. Now redirect the output of the ls command to the same file but use the appending redirection this time.
    ls >> junk
    If you look at the file you should see both the output from the who command and the output from the ls command.
  5. Make another file by concatenating text directly into it.
    cat > garbage
    You will now be able to type anything into this file that you want to. Throw some text in there just for the sake of example. When you have a couple lines, press control-d at the beginning of a new line to close the file and to stop entering text. (This is a really quick way to create a small file.)
  6. Now concatenate the files junk and garbage together into a new file called both.
    cat junk garbage > both
    If you look at the file both you should see that it has both the contents of junk and garbage.
  7. Let's look at an example of redirecting standard input. When you write someone mail, you type the message in at the keyboard. Suppose you already had the message written and saved in a file. For now, let's assume that the message you want to mail is the both file. So, mail yourself this file by redirecting the standard input to come from this file.
    zmail userid < both
    Note that userid is your RCS userid (or login). Someday I may ask you to mail me a file as a way of submitting your work. This is the way you would do it (of course, you'd replace your address with mine).
  8. Look at the file in my public directory called greek.
    cat ~escobj/public/greek
  9. The sort command accepts standard input. Note that the output of the previous cat command is the contents of the file greek. So, we can pipe the standard output from the first command (the cat command) into the standard input of the second command like this :
    cat ~escobj/public/greek | sort

Multitasking

The Commands

&
- Allows you to run a command in the background.
control-z
- Suspends a job.
bg
- Resumes a job in the background.
fg
- Resumes a job in the foreground.
jobs
- Displays all current jobs and their job number.

Some Exercises

  1. Last week when you started up emacs, you just typed emacs. You got the emacs window to come up, but you couldn't do anything from the UNIX window that you typed emacs in. But, now if you run emacs in the background by typing emacs &, you can have control over both the UNIX window and the emacs window. You can add the & to the end of any command to run it in the background.
  2. Suppose you already started emacs in the foreground (you didn't put the & after it) and now you want to run it in the background so that you can control the UNIX window. The first thing you have to do is to suspend the job. Go to the UNIX window and press control-z in it. (Note : You can't suspend a program that is not running in the foreground with the control-z keys.) You should get a brief message that says ``Suspended'' or ``Stopped''. You have temporarily suspended the job (in this case, the emacs job).
  3. Now that the job is suspended, you can type bg to resume the job in the background. Now you should have control of the UNIX window and the emacs window. Note : since the job is now running in the background, you can't suspend it with the control-z keys.
  4. If you suspended a job and then typed fg, it would be resumed in the foreground again.
  5. You can type jobs to get a list of all current jobs and their job number. These job numbers can be used as arguments to the bg and fg commands to remove any ambiguity if there is more than one job running. For example, bg %3 resumes job 3 in the background where the number 3 comes from the jobs command.

Suggestions