Chapter 6

UNIX ON THE INTERNET: A SURVIVAL GUIDE


Once you're a regular on the Internet, you'll notice that a lot of computers out there run the Unix operating system. Unix was, and is, popular among researchers and computer science departments (which made up the early Internet), partly because some of the first versions of TCP/IP were distributed free with one version of Unix known as the Berkeley Software Distribution (BSD). Many computer companies sell their machines with Unix and TCP/IP bundled in, which makes it a more popular combination than some of the other computers and operating systems, for which TCP/IP support has to be ordered separately.

You don't have to be a Unix expert to use the Internet, but it doesn't hurt to know some of the basic commands. Unix--fairly or unfairly--has gotten a reputation for being unfriendly. If you're using the Internet, however, sooner or later you'll have to deal with Unix face-to-face, so included in this chapter are some explanations of the more common idiosyncrasies and applications you may encounter when using Unix on the Internet. Knowing how to navigate through directories and use some of the basic Unix commands will make you a more powerful Internet user.

Be aware that this chapter will give you only the barest of tools to get you started and help you accomplish what you need to do. There are many different ways to do things on a Unix operating system, and these instructions offer just one way. You should also know that there are different flavors of Unix. Most of the commands here will work for whatever version you're using. If they don't, you should use the help facility (explained below), or call your local help desk to find out what the proper command or sequence of commands is. If you're interested in going beyond what's discussed here, be sure to check out the Appendix for more Unix resources.

LOGGING IN

Let's start with the basics--getting access to your Unix account. You'll need a userid and password. Typically, the login looks like this:
		login:
At this point, type your userid. The next prompt is for your password:
		Passwd:
When you type your password, it will not (and should not) display on the screen.

Important! Be sure to type your userid and password exactly as they've been given to you, preserving upper- and lowercase. Unix differentiates between the two, so if you've got the caps lock key on, you'll probably have some problems. Later on, you'll see lots of commands and filenames, mostly written in lowercase. A good rule is always to type whatever you're told to exactly as shown.

GETTING HELP

Unix may not always offer a lot of help outright, but it does have a help facility called man, which stands for "manual pages." If you ever need help with a command, type man command where command is the name of the command. For example, to learn more about man, type man man.

More

The man command uses another Unix program called more that lets you page through files--meaning it shows you one screen at a time of the file instead of letting it fly off the screen. To advance to the next page, simply hit the space bar once (typing {return} will only advance the file by one line). If you want to quit looking at the file, type q. Finally, to get a summary of "more" commands, type h for help.

Other Things to Know

Many of the applications and commands mentioned below refer to control commands. This means that you need to use your control key in conjunction with a command letter. The control key is usually represented in documentation and helpfiles by CTRL or "^". When either of these precedes a letter, you should hold down the CTRL key, and at the same time, press the command letter. For example, if you see ^G, ^g, or CTRL-G written in documentation, you should hold down the control key while pressing the "g" key (lowercase "g").

THE UNIX FILE SYSTEM

The Unix file system--the way files are organized on the computer's hard disk--is hierarchical, similar to the DOS file system. If you understand how the DOS file system works, then it shouldn't take you long to find your way around Unix systems. Since a good number of the public file archive sites are computers running the Unix operating system, learning your way up and down a Unix directory (as was discussed in Chapter 4) will come in pretty handy.

As a user on a Unix/Internet system, you have your own space on the file system. When you login, you're placed in your "home" directory, which is like your own personal file cabinet. Everyone on the Unix system gets his or her own home filing cabinet. You can organize this file cabinet any way you want--it can be very structured, neat, and tidy, or it can be extremely messy and unorganized. If you like some order to your life, then you'll be happy to know that you can create directories that house files or other directories. A directory can be compared to a manila folder, which you can use to organize and store papers (files) and other folders (directories). The ability to create subdirectories within directories makes Unix a hierarchical file system. If you looked at it from the top, it looks like a tree. (Again, the following diagram and David Letterman examples are fictitious.)

Miles of Files, Directories, and Commands

Once you start surfing the Internet, you'll be pulling down articles, books, and software, among other things, from all over the place. You'll also probably be creating quite a few files, using either the Unix editors mentioned below, or by uploading them from your own PC or Mac (if you're dialed-in to the Unix system). You'll also probably want to save the email messages you receive. Because there are so many different types of files and so many ways to create them, you should definitely have an organized system for storing them.

First of all, to see which files you have in your home directory, you can use the ls command to list them. If you type ls with no arguments, it will list your current directory (which, if you've just logged in, is your home directory). To list your Mail directory, you would type ls Mail. You can add options to the ls command to show you more about the files and directories. There are lots of options, but a common one is -l, which triggers a "long" listing. When you type ls -l, you'll see several columns of information that specify permissions, links, owner, group, size in bytes, and the time of the last modification for each file.

Here's a sample listing of David Letterman's home directory after he types ls -l to get a long listing:

sullivan-theater} ls -l

total [16]

drwx------- 4 letterman cbs 1536 Feb 13 14:34 . drwxr-xr-x 8 root cbs 29184 Feb 10 19:34 .. drwx------ 1 letterman cbs 3449 Feb 13 10:49 Mail -rw-r--r-- 1 letterman cbs 9383 Jan 17 11:03 LightBulbJokes drwxr-xr-x 2 letterman cbs 1024 Feb 12 10:39 News -rw-r--r-- 1 letterman cbs 792 Feb 6 17:51 guest-list -rw------- 1 letterman cbs 5097 Jan 29 13:59 tonights-jokes -rw-r--r-- 1 letterman cbs 5039 Jan 1 10:59 top-ten-list

The top two files indicate directories: "." is the current directory, and ".." is the parent directory.

Your listing may not have as many columns as in this example. Here, the first column lists permissions. It also indicates whether the file is a regular file or a directory. If the first character is a "d", it's a directory. In this example, there are four directories: current (.), parent (..), Mail, and News. Skip to the third column, which indicates the owner of each file. Here, "letterman" owns most of the files. The column after that is the group ownership. Letterman belongs to the "cbs" group. The next column indicates size in bytes. Sometimes you need to know the size of a file, especially if you're running out of disk space on your account. The next column specifies the date and time of the last modifications of the file. And finally, you'll see the file name.

When you login, your current directory is your home directory. You can change your current (or default) directory with the cd command. Suppose that you want to change to the News directory. You would type cd News. Now every command you type that doesn't explicitly list a directory will, by default, be performed in the News directory.

Again, another warning about case sensitivity. (The reason this is mentioned so much here is because it's such a common problem.) You need to type commands and names exactly as they appear in resource guides, email, and news. If the output of an ls command shows a file called LightBulbJokes, and you want to look at that file, you need to type the name exactly as shown; lightbulbjokes or Lightbulbjokes simply will not work. This may seem a little tedious, so you might want to use the copy and paste functions of your workstation, if they're available.

There are several commands to view files; one of the most common ones, already explained above, is more. To look at the file mentioned above, type:

	more LightBulbJokes
This program lets you page through a file. To continue to the next page, simply hit the space bar. To stop looking at the file, type q for quit. For a list of more commands, type h for help.

If you decide you don't want to keep the LightBulbJokes file anymore, use the remove file command, rm. In this case, you would type:

	rm LightBulbJokes
Or, if you want to rename the file, you can use the move command, mv. For example:
	mv LightBulbJokes LBJ
This would rename the file "LBJ."

If you forget where you are--what directory you're in--type the print working directory command, pwd. It will show you the pathname of your current working directory. You'll see a string of words separated by slashes--for example, /home/tracy/IC-files. In this particular case, the username is tracy, and her current working directory is IC-files. When "tracy" logs in, her default home directory is /home/tracy.

If tracy wants to go back to her home directory, she can issue one of two commands in this example. She can type cd, which by itself automatically puts her back in her home directory (/home/tracy) no matter where she is. Or she can type cd .. (yes, that's cd and then two periods), which will change her current directory to the parent of the one she's currently in (up one level). Remember these two "change directory" commands in case you find yourself deep in your directory tree.

Back to the David Letterman example. If he decides to organize his joke files a bit, he could create a directory called jokes. To do this, he types:

	mkdir jokes
The next thing he should do is move the two joke files he has in his home directory to the jokes directory. To do this, he'll type the following commands:
	mv LightBulbJokes jokes
	mv tonights-jokes jokes
He is using the "rename" command to move the files, but they do keep their original names in the jokes directory. To change directories to the jokes directory, David will type:
	cd jokes
Now his current directory is /home/letterman/jokes. If he types ls, he'll see:

	LightBulbJokes tonights-jokes
He can then edit or look at the two files in that directory. If he decides to change back to the parent directory, he types cd .., and he'll be one level above (/home/letterman).

If he decides later on to remove the jokes directory, he needs to use the "rm -r" command:

	rm -r jokes
This will recursively delete every file in the jokes directory, and the jokes directory entry as well. Your system may be thoughtful enough to prompt you before each file is deleted, but don't count on it. Whatever the case, be careful if you decide to use this command!

These instructions are the bare minimum, but they should get you started moving, removing, renaming, and looking at files and directories.


Sydney Is Burning

"As I flipped through my email messages one morning, I suddenly received a new one entitled 'The Sydney Bush Fires.' The mail was from my Australian keypal, and he was telling me and some of his other keypals what it was like to be experiencing the bush fires that were burning all round Sydney. Forgetting all about my other messages for the time being, I quickly wrote back and arranged to go with him to the KIDLINK IRC (Internet Relay Chat). On IRC, a place where, amazingly, people can talk back and forth, I was able to ask my friend all about the disaster. It turned out he was less than ten kilometers from the fires, he could see the flame-tinged sky and smell the smoke from his window, and he was able to tell me how far the fires were from the famous Opera House and the Taronga Park Zoo. During the next several days, I communicated through email several times more with my Sydney friend, and the fires got even closer to his house. Ultimately, he was safe. However, all week long the information about the Sydney fires that I brought to current events in my social studies class was more up-to-date than anything in the newspapers.

"That is only one of my amazing network experiences, but it is one that illustrates the way being on a computer network and having access to the Internet has changed my life in wonderful ways."

From a winning essay, "Networks: Where Have You Been All My Life?" by Rachel Weston, rweston@cap.gwu.edu, Grade 7, Georgetown Day School, Washington, D.C.

Creating Files

Perhaps one of the reasons Unix doesn't have a good reputation for being "user-friendly" is the choices of editors. They're not that hard to use--it's just that in most cases you can't use your mouse to point, click, and insert text. The three most common editors available to you are vi, PICO, and emacs. Or, you can create a file on your PC or Macintosh, and upload it (transfer it from your PC or Mac to the Unix system). The following section provides very brief survival guides for each of these.

Uploading Files to the Unix System. If you decide "to heck with learning another editor," and you'd rather upload files you created with your easy-to-use word processor on your PC, here's what you need to do. This section assumes you're dialed-in to the Unix system using a communications package like Kermit, PROCOMM, or WhiteKnight. Most of these packages come with the Kermit file transfer protocol (which is different from the Kermit communications package--confusing, yes). This section demonstrates how to transfer using Kermit. There may be other protocols available to you, such as Zmodem. Ask around if Kermit won't work for you.

Most likely the files you've created on your home computer are not text files. For example, a word-processed file is not a text file because there are a lot of codes and symbols in it known only to your word processor program. You should decide before you start transferring the file whether you need to do a binary or a text transfer. This is similar to what was described for the FTP program in Chapter 4. You can also convert a word-processed file to a text file by saving it as "text with line breaks" or "text with no line breaks."

To transfer a text file from your own computer to the Unix computer, initiate Kermit on the Unix system by typing kermit -r; the "-r" option means that the Unix system is going to receive the file. You should then "escape" back to your PC or Macintosh and initiate the sending process on your home computer by specifying what file you're sending, either through the menu system (choose "Send file") or by typing a command (for example, send file1.txt). Unfortunately, there are so many communications packages that it is impossible to tell you here what to do in your particular situation. Refer to your communications manual for the specifics. If everything goes according to plan, your text file should transfer nicely, and then it will be "on" the Unix system. You can then email it, post it on USENET news, or just look at it from time to time.

If you decide to transfer a binary file, such as software or a word-processed document, you can do that too. On the Unix side, type kermit -ir. Here the "i" option indicates that the Unix system is prepared to receive a binary file. You need to specify on your PC or Mac that you're going to send a binary file also. This may be set through a menu or a command. Again, if everything goes according to plan, you should have successfully transferred your binary file to the Unix system.

Vi. Vi (VIsual) is a display-oriented, interactive text editor, and it's very hard for newbies to figure out on their own. It's not the beginner's fault, mind you. Vi is not very helpful or intuitive at all.

Here's your basic survival guide. The first thing you should know is that it's pronounced "vee eye," not "vie." To create or edit an existing file, you type vi filename, where filename is the name of the file you want to create or modify.

When you fire up vi, you'll recognize a vi session because your screen doesn't contain much explanatory information, just the text in the file or, if the file is empty, a bunch of ~'s in the first column of every line. There are two vi modes you should know about: command mode and insert mode.

Upon initiating a vi session, you'll automatically be put into command mode. This means that most of the keys you type are interpreted as commands to vi. If you're creating a file, use the "insert" command, or i. (There are other single letters that will also put you into insert mode, such as a, o, and O.)

When you type i, it won't show up on your screen, but you will instantly be put into insert mode. (There are no status messages to indicate which mode you're in.) Now everything you type goes into vi's temporary editing buffer. When you're finished typing, press your ESC key one time to return to command mode. (If the ESC key doesn't work, try holding down the control or alt key and typing a "[". This is written as ^[.)

Here's a way to tell if you're in command mode or insert mode. If you type ESC while you're already in command mode, your terminal will beep or flash at you. So just hit the ESC key a couple of times to reorient yourself in command mode, and proceed from there.

You can move around and position your cursor by using the arrow keys. These may work when you're in insert mode, but most of the time you use them in command mode. You can also use the letters h, j, k, l (in command mode only) to move left, down, up, and right, respectively.

To delete characters when you're in command mode, position the cursor over the character to be deleted and type x. To delete a word, position the cursor at the beginning of the word and type dw (for "delete word"). To delete an entire line, type dd.

It's possible to include other files in a vi session. Suppose that you've typed a lot of material, and you want to add the contents of another file to it. Make sure you're in command mode first, then position the cursor where you want the file insertion to begin. Type:

	:r filename
where filename is the name of the file located in your current directory. Notice that when you type a colon in command mode, the cursor automatically positions itself at the bottom of the screen. That's so you can type additional information required by the command.

Finding out how to leave vi is the biggest question most newbies have right after they start it up. To quit, type :q. To write changes and quit, type :wq. To quit without saving changes, type :q!. A shortcut command to writing changes and quitting is to type ZZ without a colon (which is just really obvious!).


SUMMARY OF VI COMMANDS

Command Mode  
Insert Commands:
i 		insert before the cursor
a 		insert after the cursor
o 		"open" or start inserting in the line below the cursor
O 		"open" or start inserting in the line above the cursor
Delete Commands: 
dd 		delete the current line
dw	 	delete word
x 		delete the character under the cursor
Exiting Commands: 
:w 		write or save file
:q! 		quit without saving changes
:wq 		write (save) changes and quit
 ZZ 		write changes and quit (shortcut) 
Other:
:r filename 	include filename in buffer 
ESC 		returns to Command Mode

PICO. PICO stands for PIne COmposer, and it's the default editor used with the email application PINE, which is described below. PICO is a full-screen editor, and it's very popular among new users. If you shudder when you hear vi mentioned, see if PICO is available.

To edit a file with PICO, simply type pico filename. Your screen will split into several parts. The top line is a status line, the third line from the bottom is used for informational messages, and the bottom two lines provide a summary of the commands you can execute. Unlike vi, you are automatically put into insert mode, so you can begin typing immediately. To position the cursor, simply use the arrow keys.

To perform functions, PICO makes use of the control commands mentioned above. For example, to delete a line, position the cursor on the line, and type CTRL-k (hold down the control key and press the "k" key). To delete a character, again position the cursor, and type CTRL-d. Be sure to look at the help facility by typing CTRL-g (^G) for more information on commands. See the box below for a summary of commonly used commands.

To quit PICO, type CTRL-x (^X). The message line (three lines from the bottom) will ask you if you want to save your creation or changes before exiting. All you have to do is type y for yes or n for no. Unless you don't want to save your changes for some reason (perhaps you made too many mistakes and would like to recover the old version), you should always save. The next prompt will ask you what file name to write the changes to. It will default to the {filename} you specified at startup, so just press return if you want to write over that file. Otherwise, type a new filename.


SUMMARY OF PICO COMMANDS

^G Get Help
^X Exit
^O WriteOut (save changes)
^J Justify (format) the current paragraph
^R Read file (insert a file at cursor position)
^W Where is (position the cursor at a specified text string)
^Y Previous page (position the cursor at the previous screen page)
^V Next page (position the cursor at the next screen page)
^K Delete line
^U Undelete line
^C Current position of cursor
^T Spell


Emacs. Emacs stands for "editor macros," and a lot of people prefer using it over vi. There's a good tutorial available in emacs that will step you through all the commands you need to know. To get started, type:

	emacs filename
To learn about emacs, check out the online tutorial by typing ^H T. This means that you type CTRL-H and then the character "t."

Backward Forward Copyright © 1994 by Tracy LaQuey and Editorial Inc.


[ OBS - Home | OBS - The Bookshelves | The Internet Companion ]