ATUS Home

Beginning User's Guide - Unix

Introduction

UNIX is unlike the more familiar Microsoft Windows or Macintosh computer systems. However, once you know some basic things about how it works, it will be less frustrating. One of the most important differences is that it is case-sensitive, that is to say that uppercase and lowercase characters are treated differently. For example, I and i are considered different characters which means it is possible to have two different files, one named Index.html and one index.html. This is not possible with Windows or Mac OS. This is an important concept to remember, since many UNIX commands have options that differ only by the case they are in. Another concept that UNIX uses is what is known as a "pipe". This allows you to send the information that one command provides to another command. It is illustrated with the more and less commands described later. The purpose of the rest of this guide is to familiarize you with the more commonly used UNIX commands and how to use them.

How to use this document

This document is arranged in several sections;

Each section has a brief introduction with the associated commands listed below. It is assumed that you already know the basics of logging into and out of your account. Since UNIX is text based, it is choosy about spacing and it is case-sensitive. In order to avoid confusion, this document uses several conventions which are listed below.

command You will always see commands listed in this font. Type these exactly as written.

[-options] Options will be enclosed in brackets, like this. Options in UNIX always follow the command name and are preceded by a "–". You will see the letters of the most common options displayed in the brackets. They are described below the command, and you can use any combination of options that you choose. For example, you could have

command -xyz, command -xz, or just command with no options. Note that when you use the options you omit the brackets.

variable You will always see things that vary in this font, the most common example of a variable is a filename.

Example: Let us say you see an entry like this:

command [-xyz] filename

One example of how you would execute (type in) this command is:

command -xyz myfile

Commands are always typed at the command prompt, usually it looks something like this:

titan[1]:

When you type commands at the command prompt, the whole thing looks like this:

titan[1]: command -xyz myfile

 

UNIX

On line help

UNIX systems provide help in the form of what are known as "manual entries" or more commonly "man pages." Man pages give all the technical information for a given command as well as a summary of what the command and its options do. Man pages are often times the best resource for learning more about UNIX commands. However, in most cases you will need to know the name of the command you wish to use in order for the man pages to be useful.

Man

man [-k] cmdname Lists the manual page (or manual entry) for a given command, cmdname.

Options:

-k allows you to search all man pages for a keyword, for example man -k copy will list all manual entries that contain the keyword copy.

 

File commands

Like most computer systems, UNIX uses files to store information. The following commands are useful in working with the files in your account. In general, it is best not to alter any files that you have not created yourself or know explicitly what their function is. UNIX systems store critical information in your account that allow you to use the system and its resources in certain files in your account. Altering or deleting these files can cause problems with using your account - and has the potential to make it unusable. In particular, you should not tamper with any files that are preceded by a dot and end with the letters "rc". Normally, you will not even know that these files exist, however there are ways to uncover them. There are some cases in which you will want to create dot files yourself, but usually you will know why and what purpose these serve. Examples of these are .signature and .forward files.

Cat

cat filename Displays the contents of a file, by printing them to the terminal. Usually used in conjunction with more or less.

 

Cp

cp [-ip] filename1 filename2 Makes a copy of filename1 named filename2

cp [-ip] file(s) directory Copies the listed file(s) to directory, if the directory exists.

Options:

-i prompt before overwriting existing file

-p preserve permissions and modification times

 

Rm

rm [-irf] filename(s) Removes the file(s) named filename(s)

Options:

-i Prompt for confirmation before removing each file

-r Remove any directories listed

-f Force the removal of files despite file permissions

Warning Warning!

The rm command is permanent, that is, once a file is deleted it is gone forever. Therefore, be extremely cautious when removing files. The –i option is recommended to avoid deleting important files. The –r and –f options are usually used together to remove directories. It is very important to recognize that you should use extreme caution when using this command, as all file and directory deletions are permanent.

 

Mv

mv [-if] filename1 filename2 Moves filename1 to filename2-equivalent to renaming a file

mv [-if] filename directory Moves filename to directory, if the directory exists.

Options:

-i Prompt before overwriting an existing file with the same name.

-f Force move despite file permissions.

 

Gzip

gzip [-v] filename Compresses filename and replaces filename with compressed file filename.gz

Options:

-v Prints out compression information as well as filename information.

 

Gunzip

gunzip [-v] filename.gz Decompresses filename.gz and replaces with filename

Options:

-v Prints out decompression information as well as filename information.

 

Directory commands

UNIX systems use directories to keep track of and sort files, much like file folders in a file cabinet. Most of the principles that apply to files also apply to directories. All of the files associated with your account are, for practical purposes, contained in what is known as your "home directory." You are free to create as many other directories, or files, as you wish within this directory. The only limitation to this is what is known as your quota. Your quota refers to the amount of space you are allocated to use on the server--see the quota command later in this document for more details. There is one final important concept to understand in working with directories--the pathname, or "full" pathname. Expanding on the idea of a file cabinet, every directory and file in the system is located in the cabinet. The cabinet is a special directory called the root directory. It is symbolized by the "\". Following this directory are several other directories that hold different things from e-mail on the system to the programs that you can run. Essentially, the full pathname is how to get to the folder you want, starting from the cabinet and moving through each directory in between. For example /export/vol00/user01/joeuser is the full pathname for joeuser’s (a fictitious individual) home directory. We can see that the way to his directory is to start at the root directory, then move into the "export" directory, followed by the "vol00" directory, and so on. It is also possible to specify partial pathnames. Using the example above, let’s say that we are currently in the directory "vol00" and we know how to get to joeuser’s directory from there. We could type in the command cd user01/joeuser which would take us to his directory. Note that you do not type "/user01/joeuser", since in UNIX a preceding slash indicates, in our analogy, that you start from the "cabinet" itself.

Cd

cd dirname Changes to the directory named dirname (this can be a full pathname as well).

cd Returns you to your home directory, the directory you are in when you first log in.

cd .. Returns you to the directory in which the current directory is located.

 

Pwd

pwd Shows the complete directory path (full pathname) of the current directory.

 

Ls

ls[-al] List the files in the current directory

Options:

-a List hidden files (hidden files in UNIX are those preceded by ".", and are not shown otherwise).

-l Lists the files in the long format, showing the permissions and access times of the files.

 

Mkdir

mkdir dirname Makes a new directory named dirname.


Rmdir

rmdir dirname Removes the directory named dirname. Note: Only works when there are no files present in the directory.

 

File Permissions

UNIX uses many ways to ensure that your information on the system is safe, including requiring you to have a password to log in. One of the ways that the system protects your files from other users is through file permissions. File permissions control who can access your files and what they can do with them. There are three categories for each file that define these permissions: they are owner, group, and other. The owner group is you and only you. This category defines what you can do with a given file. As the owner of a file you can give yourself whatever permissions you want. It should be noted here that tampering with the permissions of the above-mentioned "dot" files is not a good idea, as that too can render your account useless. You can also set the permissions that your group has in accessing your file. All students belong to the students group, therefore any changes you make to this category apply to all students on the system. The final category is the "other" category, this applies to all other users of the system, including web users.

Ls

ls [-l] Lists all the files in a given directory with their assigned permissions.

See also ls under "directory commands"

Options:

-l Shows file permissions

 

How to read the output of ls -l :

Unix Screenshot 1

 

From the screenshot above:

The 1st column (1 character) shows what type of file it is [directory (d), link (l), or file (-)]

The 2nd column (3 characters) shows the permissions for the owner [read (r), write (w), and execute (x)]

The 3rd column (3 characters) shows the permissions for the group [read (r), write (w), and execute (x)]

The 4th column (3 characters) shows the permissions for all other users [read (r), write (w), and execute(x)]

 

Chmod

chmod [xxx] filename Changes the permissions of filename to mode xxx.

Options:

xxx This can be a little complicated, however, it is simple once you learn how it works. The permissions for a file are defined in the form of three numbers xxx, that gives the permissions for each category of users. Each type of permission (read, write, execute) is assigned a number. Each number x above is a sum of the numbers for each permission. This is best shown in a table.

Number

Permission

0

No permission to access file

4

Read permission-allows category to read file (read file contents only)

2

Write permission-allows category to write to file (make changes to file)

1

Execute permission-allows category to execute the file (often used with programs)


Now, let us say we as the owner of a file want to do anything with it, we take the numbers 1, 2 and 4 and add them. This gives us 7. Now, we want our group to be able to read the file and make changes, so we use the number 4 and 2. This gives us the second "x", 6. We only want any other users to be able to read the file, so we use the number 4 (note there is nothing to add to it). We combine these numbers in the form xxx to get, from our example above, 764. Hence the command to change the file to these permissions would be chmod 764 filename. Note that if we did not want to allow access to a certain group we would use 0. Also note that the first number in the mode applies to the owner, the second to the group, and the third to other users. Web pages usually use mode 644, read-write permission for the owner and read permission for all other users.

 

A graphical example of chmod:

Unix Screenshot 2

 

Miscellaneous commands

The commands listed here are of general interest and useful in different ways. They are described below.

 

Passwd

Passwd is the command that is used to change the password that you use to login to the system. It is a good idea to change your password regularly so that it remains secure and it also prevents you from forgetting it.

passwd [-f] Changes your login password. Note that this is the same password for the student modem pool, so changing this password changes the one for the modem pool as well.

Options:

-f Allows you to change the information that appears when someone uses the finger command on your account. (–f option currently unavailiable as of 9/98)

 

Finger

The finger command is useful for finding the e-mail addresses of users on the system, as well as some other information. It allows you to match a name with a login, or a login with a name using the –m option.

finger [-m] username Shows system information for the user with username.

finger Shows all users logged into the system.

 

Options:

-m Limits the search for user information to the login name only. For example, finger joeuser will find all entries that contain joeuser, but finger -m joeuser will only display the information for the user with login joeuser.

 

Quota

Quota is useful for showing how much disk space you have left to use. Each user on the system is allocated a finite amount of disk space. When you go over this amount of space, you will see messages about "being over quota". When this occurs, you usually have about 7 days to delete files that you no longer need, generally old e-mail if you keep that on the system or file attachments that have been exported. The quota command gives you a way to see how much space you are using so that you can clean out files you no longer need before you see error messages like the one above.

quota [-v] Shows amount of space available for use in your account (always use with –v option).

Options:

-v Needed so that all space used is shown.

 

Lpr

Lpr lets you print a file to any printer on the network. It can be a text file or a postscript file. Printer names for various labs on campus can be obtained through ATUS.

lpr [-Pprinter] filename Prints a standard text file, filename.

lpr [-pPprinter] filename.ps Prints a standard postscript file, filename.ps.

Options:

-Pprinter Specifies printer to be used (Note there is no space!).

-p Specifies that the file is not a standard text file, but rather postscript instead.

 

More and Less

More and Less are commands that are useful when you execute a command, but too much information is printed to the screen preventing you from reading all of it. They can each be used in two ways described below.

more filename Prints the contents of a file one screen at a time

command |more Prints the output of a command one screen at a time.

less filename Prints the contents of a file one screen at a time

command |less Prints the output of a command one screen at a time.

Note that the "|" character is known as a pipe. It is usually found on the same key as the \ character, just above it.

When using more or less:

Pressing q exits the program

Pressing the space-bar prints the next screen of information.

Pressing b goes back one screen of information.

more exits automatically when the command is finished or it has displayed all the contents of a file.

In less only:

Pressing ¯ moves down one line.

Pressing ­ moves up one line.

When (END) appears at the bottom of the screen, press q to return to the command prompt.