CSE 271 Lab 1: Using X-Windows and Editing Files

X-Windows

Welcome to X-Windows on Solaris. Today you will sit at a workstation, log in, and explore X-Windows as well as a number of UNIX commands.

On the Suns you are presented with a login window which includes the ability to choose a desktop environment (as an option before you login). Try one of them---I use the Java Desktop System (the most modern, similar to what you might see in Linux). CDE is very old, and won't be part of the next version of the OS. AfterStep is modeled after the NextStep environment, and is pretty classy and fast. Choose any for now, and you can choose a different one later. In fact, I encourage you to try additional environments (after completing the lab exercises).

Window Managers. Once you have logged in, explore the interface. Notice that each of these window managers treat application windows differently. Buttons to minimize, close, resize, etc. are all functions that can be mapped by the window manager. If your window manager didn't automatically open a shell console or terminal window, look for the tool that will do so and open it. You'll need it for the rest of this lab. Once you have one open, you can open additional ones the same way, or start additional shells by typing xterm from the one shell that is running.

Copying and Pasting. The X-Window system provides a simple and intuitive way to copy and paste using a mouse. Whenever you highlight text (anywhere) using the left mouse button, that text is available for pasting. Pasting is performed by clicking on the middle mouse button (or scroll wheel or both buttons together on a simpler two-button mouse).

Web Browsers. If the window manager is has a link to an old web browser or if it is missing, from your shell you can type firefox to run a reasonbly modern web browser.

Editors. Similarly, some window managers may have a link to editors, but probably not for vi or emacs. You can type them at the shell. If you run emacs, you'll get the X-window interface automatically whenever it can run (unless you specify the -nw option to prevent it).

Office Applications. Some windowing environments will include menu items for office applications such as word processors and spreadsheets. An additional one (if it is not included in your window manager) that might be of interest is OpenOffice and a popular branched version called LibreOffice. OpenOffice/LibreOffice is available for many platforms, including Solaris, Linux, and Windows, and can read and write Microsoft Office compatible files. To start it, just type soffice.

Document Viewers. The Suns include programs to view PDF and PostScript files. For PDF, you can use acroread (Adobe Reader) or gpdf. For PostScript, try ggv. Try these out by viewing /home/brian/cse271/refcard.pdf.

Remote Execution. One thing that makes X-Windows great is the ability to log into a machine remotely, and then have a program use your local display. You can do this too -- just ssh from your machine to another, such as another system in this lab (that is, type something similar to ssh -X sunlab), and then run a program (that uses windows) on the other machine and see it show up on your screen. This separation of display and execution makes it easy to use high-powered, centralized servers, even though you might not be able to sit in front of them. Lehigh provides a number of such computational servers (such as altair.cc.lehigh.edu which has 32 processors and 128GB of RAM and runs Linux) and the Lehigh Application Farm (LEAF) which is a collection of servers (each with 12GB RAM and running Linux) that is open to everyone at Lehigh (via ssh to leaf.cc.lehigh.edu).

Printing

Often you will want to print a file. UNIX printing systems are typically configured to handle (print) plain text files and PostScript files. There are two major approaches to printing under UNIX: the System V and BSD command interfaces. Both work on our Sun installation.

What printers are available?

What are the names of printers not in this room?

To print a file to printer pl122-ps (the black and white printer in here):

PostScript is the default printer language for UNIX printing; however, the printing subsystem will convert a text or postscript file to the appropriate printer language if necessary. For example, you can usually print a PostScript file to a dot matrix printer (even though a dot matrix printer typically as no idea what PostScript is).

To see what documents are currently queued for printer pl122-ps:

Removing a queued document 42:

While we can print a postscript file from the command line (e.g., lpr -Ppl122-ps file.ps), for other complex file types (like PDF) you'll need to run a viewer program that can generate PostScript instead.

UNIX includes other utilities to help manage PostScript files. One that is helpful to know and use to save trees when printing your programs is mpage. mpage takes text or postscript files as input, and generates postscript placing multiple pages on each side of the piece of paper.

Editing Files

Do you have a favorite editor? I'm not talking about a word processor. What do you use to write code? Is it available under UNIX? There are many text editors available for UNIX systems, including pico, nano, vi, vim, emacs, ed, and many more. Not all of them are installed on the Suns.

To become a productive programmer, you must become productive with your editor. Various versions of UNIX may come with multiple (different) editors, but they will always come with a version of vi and probably emacs. Since the choice between vi and emacs is akin to a religious question, you will get to make up your own mind about which to use. In this section, you will become familiar with one of them, and our next homework will reinforce your knowledge.

Like most UNIX commands, vi and emacs are easy to start -- just type the name of the program at the prompt. But perhaps more important than how to start them is how to quit. Some less-common UNIX commands will automatically bring up an editor, and it may not always be your editor of choice. So, if you are an emacs user, you need to know how to quit vi. The answer is :q (that is, a colon followed by a q, followed by the enter key). If you are already in editing mode rather than command mode, first press the ESCape key, then :q (or perhaps :q! to exit without saving).

If you are a vi user, you need to know how to quit emacs. The answer is C-x C-c (that is, control-x followed by control-c). If the file has changed, emacs will ask you whether to save. If you are in some strage emacs mode and C-x C-c does not work, first type C-g (control-g) to abort the current operation, then C-x C-c should work.

vi

vi, or more often, vim, is installed on almost every UNIX-based machine. To learn about vi, read Hahn Chapter 22. If you did not bring your book, or would like another reference, try the tutorial from U. Hawaii: Mastering the VI editor.

emacs

GNU Emacs

Emacs is one of, if not the, most popular and full-featured editors. It is available for most every platform/OS. It is more than just an editor; every keystroke and sequence of commands executes a macro that can be reprogrammed, and as a result emacs is quite flexible. Emacs can

Emacs History

Emacs is the extensible, customizable, self-documenting real-time display editor. It was originally developed in the 1970s by Richard M. Stallman. (Stallman visited Lehigh and gave a talk in 2007.) The name was chosen as an abbreviation of Editor MACroS. Emacs development continues. Modern emacs:

Running Emacs

Start emacs by typing emacs (and return) at a shell prompt. If you are running within X-windows, a new window will open Otherwise, emacs will run full-screen (within the starting terminal). Menus are available (use F10 to operate if not running within X-Windows).

Operating Emacs

Emacs provides many, many keyboard shortcuts (as well as longer commands). Every keystroke is a command to emacs; keys that have printable characters are generally bound to a command that prints itself. Some combinations of keystrokes have special meanings Example command sequence: C-x C-f will prompt you for the name of a file to open.

The Meta Key

Modern PC-style keyboards do not have a "Meta" key! Instead, often the ALT key will work. If not, the ESC key can be used, but as a separate keystroke (since it is not a key modifier like CTRL, SHIFT and ALT) which is slower.

Essential Commands

Files Created By Emacs

Emacs will let you open new (nonexisting) files. If you close a file that was modified (without saving), it automatically leaves a temporary file called #filename# . If you edit and save an existing file, emacs renames the old file as filename~ .

Emacs Resources

Emacs is a large, complex editor. Some useful references:

Task

Use your new favorite editor to create a file with 100 identical lines of "xyz123 says Hello Lehigh University" (where you replace xyz123 with your username). Use key commands to copy and paste the line rather than typing by hand. Even better: see if your editor supports pasting n times rather than doing it manually 100 times. Put your name at the top of the file. Save this file as hello.txt.

Print your hello.txt file using one of the command-line methods described earlier. It should print your text on both sides of the paper.

Often it is helpful to reduce paper used in printing. Learn about the mpage utility (try man mpage) and use it to print a 2-up (two pages per side) version; it should get all of the hello.txt file on the first side of the paper.

Okay, that's it. Now you can try out some of the other windowing systems.

Homework HW1 (due Friday)

If you have time you might start working on HW1. It is almost as simple as HW0.

Reminder: your CSE/ECE Sun account is entirely separate from your university account.

Please test that email to your CSE/ECE account is forwarded to wherever you read your email (since the TA and I and the automated grading system may send messages to you there).

Looking Ahead

Friday's quiz will only be on material from class or (prior) assigned readings. Friday we will also talk further about using UNIX.

Last revised: 16 January 2013, Prof. Davison.