Getting Started With The UNIX Operating System

Documentation Notes

All examples used in this document will be from the rci or eden systems. User input will appear in this typeface . System output will appear in this typeface . Text that is in italics represents place holders for specifics that you would supply. The notation <CTRL>d means you hold down the control key while typing the indicated character (in this case d). This document is intended to be viewed on the web and used as a self-paced tutorial, and presumes that you will be using either an eden or rci account. All commands listed in this tutorial are linked to a description of the command, simply click on the command to go to that description.

Introduction

A computer's operating system is a "Master Program" that interprets the commands issued and then causes the specified actions to be taken. UNIX is a multi user, multi tasking operating system (each user gets a portion of the computer's time and many operations are performed simultaneously) whose development began at AT&T Bell Labs in 1969. Many versions of UNIX exist but the two main "flavors" of UNIX are based on AT&T's System V or Berkeley's 4.3BSD (Berkeley Standard Distribution). This document describes Sun Microsystems Solaris (a BSD and System V blend) UNIX which is widely used at Rutgers.

In order to access a UNIX computer, you must have a valid account. If you are a Rutgers employee or a registered student at Rutgers you may create an account for yourself. For instructions in how to do this see the NBCS document "Creating Accounts on OIT Systems" (GEN00301) .

Do not, under ANY circumstances give your password to anyone else (including RU-OIT staff); the only one who should have access to an account is the single person who it was assigned to and as such that person is held responsible for ALL activity on their account.

NetIDs/Usernames and Passwords

A NetID/username on RU-OIT computers must have no more than eight (8) characters and can be almost any combination of lowercase letters and numbers that starts with a letter. The current rules for acceptable passwords on NBCS computers are:

Your password must be no less than six (6) and no more than eight (8) characters long.

It cannot contain any 4 consecutive characters from your name, your IID, or from the contents of your .plan, .project, .forward, .qmail, or .signature files.
You cannot reuse any of your previous 5 passwords.
Your password must also contain a minimum of 3 character classes. The characters on the keyboard are grouped into 5 character classes. They are:

lowercase letters (a-z)
uppercase letters (A-Z)
numerals (0-9)
punctuation
special characters

Spaces tabs backspaces (deletes) and carriage returns are not allowed.

To change a password on rci, go to http://www.rci.rutgers.edu/tools.php, select "passwd" and follow the form for changing your password.

To change a password on eden, go to http://www.eden.rutgers.edu/tools.php, select "passwd" and follow the form for changing your password.

Logging In and Out

When you connect to a NBCS computer you should see something like:

Solaris 2 (amenti.rutgers.edu) (pts/92)

login:


At which point you would type in the NetID/username for your account on the system you are connecting to followed by a carriage return (the <ENTER> key). You will be prompted:

password:

At which point you would type in the password for that account. NOTE you will not be able to see the password as you type it. Please note the systems announcements that are displayed as you first login. These are readable via the eden or rci web pages:

www.eden.rutgers.edu
www.rci.rutgers.edu


The systems status is also available on the eden and rci web pages under "System Information".

At the end of your session you log out with either of the following two commands:

logout
exit


By default NBCS systems have disabled logging out with <CTRL>d . To prevent anyone else from accessing your account, always log out of your account when you are through and do not leave your account logged in and unattended in any public area.

Practice 1

Command Format and Execution

A command is an instruction to the operating system to perform a specific task. UNIX is case sensitive, which means that file names or commands that are spelled the same but have different capitalization are interpreted as different files/commands. The UNIX command format is:

command-name [ options ] [ parameters ]

The square brackets are used here, as in the UNIX manuals, to indicate that the enclosed items are optional, you would not normally type them.

A command-name is usually an abbreviation of the action of the command. For example "ls" will list a directory's contents, "mv" will move or rename a file, and "cp" will copy files.

An option is a single letter or number preceded by a space and a hyphen '-': "ls -l". Most options may be grouped together with a single hyphen or separated with a space and a hyphen for each. The following commands achieve the same result:

ls -lA
ls -l -A


See the command descriptions document "Basic UNIX Commands & Metacharacters" for a brief explanation of this and other commands.

Parameters are usually file names which may include the "path" (see Directories and Paths) or wild cards (see "Basic UNIX Commands & Metacharacters").

To execute a UNIX command simply type in the command-name and all options and parameters required to achieve the effect desired. After a command has been entered and any output displayed, the computer will simply issue another prompt, unless there has been a problem in its execution or the execution of the command requires some interaction.

Getting On-line Help: Man pages

UNIX has a fairly complete set of documentation, called man (manual) pages, that is available on-line. Every command or program should have a man page. To access man pages, use the man command. For example, to get help on the "ls" command, type:

man ls

In order to use the man command, there are some things you should know.

First, the program used to display the man pages is called more (See a brief usage description of the "more") command in the command descriptions document "Basic UNIX Commands & Metacharacters").

Second, for substantial programs, the manual pages do not give every detail you may need. They should tell you how to run the item specified but be short enough to read on your screen. So "man cc" will tell you how to run the C compiler and list all of the options, but it will not be a C language reference manual. There are separate manuals for programming languages, the mail system, the document processors, and certain other complex pieces of software. Generally the man page will refer to this documentation if it exists.

Third, many of the man pages were written by technical people for technical people and assume the person reading them knows more about UNIX than a novice will.

Fourth, the man pages are organized into chapters. For example, if you issue the command
man -k unlink ("man -k" is described later in this section) to find out what documentation is available on "unlink", it will offer man pages from chapters 1, 2, 3 and 9. It is useful to know which chapter describes which types of commands. So if you were looking for the FORTRAN subroutine information, you would look in chapter 3. Most of the time general users will only be interested in those items in chapter 1. The chapter topics are:

Chapter

Topic

1

User Commands

2

System Calls

3

Subroutines

4

File formats and conventions

5

Headers, tables and macro information

6

Games and demos

7

Special Files

8

Maintenance items for system managers

9

Device drivers and kernel functions

Some chapters have subsections, chapter 1 for example:

1

User Commands

1b

BSD Compatibility Commands

1c

Communication Commands (not usually of interest to general users)

1f

Form Menu Language Interpreter (FMLI) Commands (not usually of use to general users)

1m

Maintenance Commands (few of interest to general users)

The man command is useful when you know what a command's name is. But if you can't remember the name of a command, the man command can't help because you can't tell it what to look up. The option "-k" causes " man" to list the title lines of the man pages that have the supplied keyword in it. So:

man -k remove

would show all the title lines that contain the word "remove". Often "man -k" will return so many entries that it is overwhelming. Adding ' | grep "1" ' after the 'man -k' command, as in:

man -k remove | grep "1"

will filter the output to show only those entries containing the character "1" (Pipes such as the above are explained in the "Intermediate Use of the UNIX Operating System" document). Should you see a command that is listed twice in different chapters (1 and 3) or sections (1 and 1b) you can specify the chapter/section with the man option "-s" as in:

man -s1 rm

Generally the title lines contain most of the keywords people would use in looking for them. Using combinations of "man -k" and "man", you should be able to find most of what you want to know about UNIX.

Practice 2

Files

A file is an area of storage that is assigned a name by the user. Anything can be put into files; programs, data, or text. Each file has a name that is chosen by the creator of the file. Names can be from 1 to 255 characters long and can safely include letters, digits, and the characters '.', '-', and '_'. A common naming convention used to organize files by their contents adds a '.' and a short description of the file. The part of the name after the '.' is called the extension. A file named demo.c would be a C program code file and data.txt would be a text file. Executable files often do not have extensions.

Short files may be displayed with:

cat filename

the cat command concatenates (displays) the named file to the screen. Longer files can be viewed with:

more filename

To scan a file for lines that contain a particular string of characters you can use the grep command. The command:

grep "the" file.name

would list all of the lines in the file "file.name" that contain the string of characters "the". Note that lines with 'then', 'father' and 'soothe' all would be displayed not just those with the word 'the'. To list the files in the current directory type:

ls

To show more information about a named file use "ls" command with the "-l" option as in:

ls -l Project1
-rwxr-xr-x 2 jqsmith users 512 Mar 12 12:02 Project1


The first character of a long listing indicates the type of file a particular file is. The three most common types of files encountered are; ordinary files denoted by a "-", directories denoted by a "d" and symbolic links denoted by an "l". For example:

ls -l

total 16424
-rw-r----- 1 jqsmith facstaff 383 Jul 20 13:26 File.txt
drwx------ 4 jqsmith facstaff 512 Apr 16 15:20 Maildir
lrwxrwxrwx 1 jqsmith facstaff 28  Jun 17 14:31 file.lnk ->
/rci/u2/jqsmith/File.txt
	

Note: the last two lines above are actually one line that is too long for the screen and wraps around to the second line. Other types of files (explained in "man ls") are denoted with other characters in a long listing.

To copy (duplicate) a file named "file1" into another named "file2" use the command " cp", as in:

cp file1 file2

A file can be renamed (moved) to a different name or directory with the "mv" command, as in:

mv file1 file2
mv file3 dir1


The above renamed "file1" as "file2" and moved "file3" into the subdirectory "dir1". To remove (delete) a named file use:

rm filename

To remove all files in a subdirectory and the subdirectory use "rm" with the "-r" option as in:

rm -r dirname

Caution: in UNIX there is no undelete command. To undelete a file it will have to be restored from the last (nightly) back up. All changes to the file between the back up and the deletion will be lost. If the file did not exist at the last back up it will be completely lost. See the description of rm for the "-i" option. Likewise the commands cp and mv may overwrite pre-existing files and thus using the "-i" option with these commands to cause them to ask before overwriting an existing file may be desirable.

Space on computer disks is limited so each user is allotted a set amount of disk space they may use permanently, this amount is known as a quota. Additionally users are permitted to go over their quota for one week up to a hard limit beyond which they cannot go. To check your quota status issue the command:

quota -v

Note on eden 'quota -v' displays more information than it will on rci. To check the disk usage in kilobytes of your home directory, login and issue the command:

du -k ~

The output from 'du -k' could look like:
 10  /rci/u2/jqsmith/Maildir
 1   /rci/u2/jqsmith/UNXclass/UStoreIt
 1   /rci/u2/jqsmith/UNXclass/NoWrite
 1   /rci/u2/jqsmith/UNXclass/RemoveMe
 68  /rci/u2/jqsmith/UNXclass
 478 /rci/u2/jqsmith

The last line is the total for the current directory and all subdirectories. To reduce the amount of space a file takes up use the command:

gzip filename

To expand the file reduced in the above use the command:

gunzip filename.gz

Practice 3

Directories and Paths

Files are stored on computer disks that are attached to the computer. A disk can hold thousands of files belonging to many different users. Each user is assigned a portion of a disk for their own use; this space is called a directory. The normal login procedure connects you to your 'home' directory, which is referred to by your user name. If you issue the cd command without indicating any directory name you will be returned to your home directory. When you refer to a filename without any special qualification, you are referring to a file by that name in the current directory.

There are many different directories on a disk. A user can have a home directory that contains a directory (a subdirectory). For example, John Q. Smith can have a home directory 'jqsmith', and a subdirectory 'UNXclass'. The subdirectory 'UNXclass' is contained within 'jqsmith'. Subdirectories are also referred to as child directories and the directory containing the subdirectory is referred to as the parent directory.

This, then, falls within the structure of the entire UNIX file system, which can be thought of as an upside down tree (as in a family tree). The top directory is called root, and is noted as "/". Next come other directory names, such as "usr", "etc" and others. On NBCS systems, there is also a directory at this level named for the computer system (e.g. "rci" or "eden") which has subdirectories named "u1", "u2", or some other "u#"; which in turn contain the user directories. Depending upon the command used the system name in the path may appear as some other name (i.e. avernus, nirvana), these are aliases for the system name. As shown below, the directory "jqsmith" is a subdirectory of "u2", which is a subdirectory of "rci", which in turn is a subdirectory of the root directory.

To specify the 'full name' of a directory (or file), you must start with the root and then work towards the desired directory or file. Each directory is followed by a '/ '. To use the previous example, the full name of a file in the directory 'jqsmith' is: '/rci/u2/jqsmith/ filename '. This full pathname contains: root (/), a subdirectory (eden), another subdirectory(u2), another subdirectory (jqsmith), and then the file ( filename ).

The directory you are currently in can be indicated by a '.' (period). The parent of the current directory (the one immediately above the one you are in) can be indicated by '..' (two periods). If you are in the eden account "/eden/u2/jqsmith", a file in the subdirectory "UNXclass" may be referenced by the full pathname "/eden/u2/jqsmith/UNXclass/ filename ", by "./UNXclass/ filename ", or by "UNXclass/ filename ". If the current directory is again jqsmith, you can refer to a file in the parent directory with "../ filename " or by the full pathname "/eden/u2/ filename ". The '.' and '..' notations are 'relative pathnames' because the reference is relative to the current directory.

Another relative pathname notation that provides a short cut to a user's home directory is to precede the NetID/username with a '~' (tilde). The home directory of J. Q. Smith may be referred to as "~jqsmith", your own home directory may be referred to as "~/". This is useful when copying from the current directory to your home directory, as in:

cp filename ~/

Five of the most commonly used directory related commands are as follows:

Command Description
ls list contents of specified directory or files, if nothing specified list current directory
pwd print working directory print the full pathname to the current directory
cd change to the specified directory, if nothing specified go to home directory
mkdir make subdirectories
rmdir remove (delete) empty subdirectories

Practice 4

For More Information

Questions should be directed to the NBCS Help Desk, Room 013, Hill Center, Busch Campus, (732) 445-HELP (4357). You can also send electronic mail to the address help on any OIT system (e.g., help@rci.rutgers.edu or help@eden.rutgers.edu) or you can visit the NBCS FAQ at http://faq.rutgers.edu.

Copyright © 2007 Rutgers, The State University of New Jersey, OIT/NBCS, Help Desk. All rights reserved.

7/31/07 Dan Koft, author

Rutgers University
Office of Information Technology

UNIX 1