Stranger in a Strange Land: getting the hang of Unix

First Published: Online Access
Date Published: April 1994
Copyright © 1994 by Kevin Savetz


As you explore the Internet, chances are that you will use a computer system that works with the Unix operating system. If you're only familiar with DOS or Macintosh computers, trying to use Unix can make you feel like a stranger in a strange land. Read on, and you will have a better understanding of the basics of Unix - and you'll learn how to find more information about Unix when you need it.

Unix is one of the most popular operating systems on the Internet. It is popular because it is available for a wide variety of computer platforms and because it is a multi-user, multitasking environment. This means that several people can use a Unix computer simultaneously - and each person can run several programs at once. This makes Unix is a very powerful system.

Unix was developed in 1969 at Bell Labs. Since its creation, Unix has seen countless updates, revisions and spinoffs. Today, there are flavors of Unix with names like SCO Unix, BSD and System V. These systems work in very similar ways, but it is important to know what version you're using when you have a question or are looking for a book on Unix.

The following information will show you the basics of getting around with Unix. Most Unix commands are very powerful. With practice you will be able to combine commands to easily perform otherwise complex tasks.

Logging in and out

To access a Unix system, you'll need the system administrators to set up your very own "account." Every person who is authorized to use a particular Unix system has an account - when you want to use the computer, you tell it your account name and a secret password. The computer uses this information to verify who you are, give you access to the information that belongs to you and keep others out of your files. If you're legit, you'll see the Unix "prompt", the sign that the computer is ready to take a command.

If you use DOS, you're familiar with a prompt like C:\>. Unix prompts vary from system to system, but yours is most likely to be a dollar sign ($) or a percentage sign (%).

When you log on, you may also the system "message of the day" (or MOTD, pronounced mot-dee) announcing anything the system administrator thinks you need to know. You may also see a message if you have any unread electronic mail.

To log off the system, simply type "logout". It is important to do this to tell the computer you don't plan on using it for a while. This will prevent others from walking up to your terminal and looking through your files.

About files and directories

If you've used any other computer operating system, you are familiar with the concepts of files and directories. Files are individual collections of information stored on a computer (for instance, a letter to Aunt Zelda, a picture of the moon or a game program.) Directories allow you to place files in a logical manner so you can find them later. Unix files and directories are very similar to those on DOS computers.

Your account has a "home" directory, the directory you use by default when you log on to the system. You can change your current directory, list a directory's contents, and create and remove directories that are part of your home directory. Unix uses a hierarchical directory structure, like DOS. This means that there is one "root" directory, and many sub-directories to store files in. Here is a small example of what one might look like:


        _______________(/)______________________________
       /      /           \       \                     \
     bin     lib           etc     files_____________   usr
            /                     /        \        \
           sys                  stuff       \     junk
                                             \
                                              home
                                            /
                                      waffle
                                     /
                                mystuff

A file in the "mystuff" directory can be referred to as: "/files/home/waffle/mystuff/filename".

This is referred to as the filename's "full path". The first / must be there for it to be a full path. If you leave it off, Unix will look for the file starting in the your present directory. This is useful because having to constantly refer to files by their full pathnames would get tedious. If you were in "waffle"and wanted to refer to "filename" in "mystuff" you could call it "mystuff/filename" Or, if you are already in "mystuff", just use "filename"

If you use DOS on your home computer, note that Unix uses a forward slash between directory names instead of a backslash.

If you use DOS, you're also used to restrictive filenames with eight letters, a period and an extender of three more letters (for example, GRANDMAS.LTR). If you use a Macintosh, you have the luxury of filenames of up to 31 characters. Depending on what flavor of Unix you're using, you may be allow filenames from 14 to 255 characters. And, unlike DOS, which only likes A-Z, 0-9 and the underline in filenames, Unix filenames can contain just about any character you can type on the keyboard. (Some characters are possible as part of a filename, like the space character, brackets and the asterisk, but can get you in sticky situations later. It's best to avoid using them.)

File manipulation

Below are some important commands for manipulating files and directories. First thing's first, though: use and love the "man" (manual) command. Typing "man cp" (for instance) will tell you everything you could want to know about the cp command. Type "man man" and "man intro" for general system help. Most of the following commands take special options, called arguments, for tweaking how they work. There isn't room here to list each command's options and arguments, so make judicious use of the man command.

pwd - this command stands for Present Working Directory, and it will tell you what directory you're currently in. Log on to your system and type pwd to find out what your home directory is called. Mine is /files/home/waffle.

ls - lists all the files and directories under your present working directory. There's a problem, though: the ls command doesn't tell you whether you're looking at the names of files or directories. Not to worry: if you type ls -CF you'll get a nicely formatted list, with executable files (programs) indicated with an asterisk and directories indicated by a slash.

Some files in Unix are normally invisible (or, hidden files.) Any filename that begins with a period, such as ".newsrc" and ".login", aren't normally shown with the ls command. You can see them, however, if you explicitly ask to see all files by adding the "a" argument to the ls command: type "ls -a" or "ls -aCF" (yes, capitalization matters!) to see your invisible files. Invisible files usually specify your system configuration and preferences information - or, perhaps you simply have something to hide.

cd - stands for change directory. You can move to a directory that is under your present directory by typing something like "cd mystuff". To move to the directory above your current one, type "cd .." (that's two dots. Why two dots? It's a mystery to me.) If you know exactly what directory you want to go to, you can type a command like "cd /lib/sys".

cp - is an abbreviation for copy. Not surprisingly, the cp command lets you copy a file. Typing "cp file1 file2" will create an exact copy of file1 in your present directory. Typing "cp file1 /files/home/wombat" will create a copy of file1 in another directory.

mv - is an abbreviation for move, and lets you move files around directories. Moving a file copies a file to your specified directory then deletes the original.

rm - stands for remove. This command will let you erase files that you no longer need. Be careful! There is no "undelete" command in Unix; once your file is gone, it's gone forever. rm file2 will erase one file in your present directory. Typing rm * will delete every file in the directory. In Unix, like in DOS, the asterisk means "all files".

cat - stands for "catenate," an obscure word meaning "to form a chain or series". In its most basic use, cat works just like DOS' TYPE command: it displays the contents of a text file. Actually, you can use it to display the contents of any file, but binary files (like programs and digitized pictures) will only appear as garbled data. To display a file, just type "cat letter_to_grandma" and the computer will dump the letter to your screen. If the text in the file is too long, the beginning will scroll off the top of the screen faster than you can read it. Which brings us to the next command...

more - which shows you the contents of a text file one page at a time. To use it, type "more letter_to_grandma". After each screenful of text, you'll see the word "more". Strike the space bar to see the next page of text. Your system may also have a program called less, which does the same as more, only better. Just as they say, less is more. :-) As always, type "man less" or "man more" for complete information.

chmod - can be used to change the permissions of files. Unix permissions can be tricky. Remember that Unix is a timesharing system that can be used my many people simultaneously. You might want to keep some of your files - for instance, your electronic mail - private, but let other users read or modify certain files. So chmod, which stands for "change mode" makes it possible to allow or deny yourself, all system users or certain users to read, write or execute your files. For more information (you saw this coming, right?) type "man chmod".

Internet Tools

Ah, the Internet, the vast meta-network that is probably the reason you're learning Unix. Internet commands are straightforward, but can contain subtle nuances of their own. Internet tools you should become familiar with include: telnet - allows you to run programs on other computers on the Internet. For instance, to use the University of Michigan's "Weather Underground" program to find the weather in any city, type "telnet 141.212.196.177 3000" and follow the directions.

ftp - stands for File Transfer Protocol. This program allows you to connect to other computers on the 'net and copy files to and from them. You normally need to have an account and password on the remote computer to get and place files. You will also hear the term "anonymous FTP", which means using the ftp program to log into a computer that allows anyone to look around and download files. For example, if type "ftp wuarchive.wustl.edu", log in as "anonymous" and use your e-mail address as your password, you'll be able to peruse a huge library of software, information and graphics.

rn or trn or nn or others - are programs that allow you to read the Usenet, a huge distributed bulletin board system. The Usenet contains a wealth of ongoing discussions on every topic imaginable.

gopher - allows you to "burrow" around the Internet. Gopher is one of a new breed of tools that are making the Internet easier to use.

Mail or elm or others - these programs let you read and send electronic mail. Mail is a very simple program that is available on every Unix system. The elm program will only be available if your system administrator specifically put it there. If it is, you'll find it much easier to use electronic mail than with Mail. Other fine mail programs are available also.

Random commands

Here are some commands that are important, but don't really fit in with other groups: man - OK, I already mentioned this one, but I'm mentioning it again to make sure you know how to RTFM (read the manual.) The man command shows you the "manual page" for a particular command. For instance, "man ls" will give you lots of information about the ls command.

vi or emacs or others - are text editors, programs that allow you to create text files (such as e-mail messages, programs or letters to Aunt Zelda). Ask your local guru what editor you should use. The vi editor is simple but not exceptionally easy to learn. In contrast, emacs is a software behemoth that will edit files, tell your fortune and teach you to make cookies. (Really.)

lpt or print - may let you print a text file on a printer connected to the Unix computer. Two caveats: first, never try to print a non-text file - anything that looks like gibberish when viewed onscreen with the cat command will look worse on paper. Second, if you're hacking from a college computer lab or your office and you know there's a printer down the hall, feel free to use the print command. However, if you're using a dial-up Unix system hundreds of miles away, don't use the printer unless you intend to drive there to pick up your printout!

grep - stands for Global Regular Expression Print, which is a verbose way of saying that this program will search through files and output any lines that contain text that you specify. If you've ever read Usenet news, your home directory contains a hidden file called ".newsrc" which lists all the newsgroups available to you. Typing "grep amiga .newsrc" will list all the lines in the file that contain the word "amiga".

passwd - allows you to change your password. Typing passwd will prompt you for your old password then ask you to type your new password twice. Passwords you type should never be visible on your screen.

compress and uncompress - This pair of programs will compress or decompress a file (or files) of your choice. Compressed files end in the extension ".Z" and take up less disk space than uncompressed ones. Many of the files available via the Internet's FTP tool are compressed to save space and reduce transfer time. Similar to .ZIP files on a DOS computer and .SIT files on a Macintosh, Unix's compressed files take up relatively little space, but aren't useful while in compressed form. To use these commands, just type "compress filename" or "uncompress filename.Z"

For more information

This article has just given you enough information about Unix to be dangerous. Unix is a complex operating system made up of hundreds of commands, oddball nomenclature and countless little quirks. Don't worry - the Internet is rife with beginner's information about Unix. To explore more of the basics, read:

If you prefer learning from traditional books, rent a forklift for your return trip from the library or bookstore. Dozens of fine Unix books abound. Be sure that the book you pick out is tuned to the version of Unix you use (for instance, System 7 or BSD.) If you're not sure which book to read, start with one of these:


Sidebar: Ten things not to use as your password

On any Internet system, not just Unix, your password is the only thing standing between you and disaster. If someone should guess your password, he or she will be able to read your electronic mail, snoop in your files, delete your work and post electronic mail or Usenet news that appears to come from you. Each of these things can be embarrassing, annoying and dangerous.

Unix systems use a tricky feature called one-way password encryption. When you first choose a new password (for instance, with the passwd command) the computer encrypts your password - so thoroughly that it can never be decrypted - and only stores the encrypted version. Later, when you type your password while logging in, the computer encrypts your guess using the same method and compares the encrypted version of your guess to the encrypted version of your actual password. If they match, you're allowed in.

Although your password can't be decrypted, you're never perfectly safe. Unscrupulous crackers can use the encryption routine to stab guesses at your password. At least one computer program is available that can quickly and silently encrypt every word in the dictionary and compare it to the list of encrypted passwords on your system. Therefore, if your password is in the dictionary, you can get zapped.

A variety of other passwords that aren't in the dictionary are also bad choices because they're very easy to guess. Here is a partial list of passwords not to use:

password
opensaysme
letmein
your initials
your login name
your cat's name
your spouse's name
any information that can be found by "fingering" your account name, such as your phone number, name, etc.
any word that's in the dictionary
To be as safe as possible, make your password a bunch of unrelated characters, such as "K#*2ww>". Use a combination of upper and lower case letters, punctuation and numbers. If you find this type of password too hard to remember, try using two unrelated words separated by a punctuation mark, like "explore*grasshopper".


Articles by Kevin Savetz