30 June 2001
Copyright, Information Technology Services
training@cc.utexas.edu
The University of Texas at Austin
This short course covers the basics of using the UNIX operating system. After completing the course, you should be able to:
Connect to an ITS UNIX system, log in, log out and change your password.
Create directories, copy files, delete files and perform basic file management.
Get help using the UNIX man pages, printed documentation, the World Wide Web, and other sources.
Create and edit a simple file with an editor.
ITS provides access to a number of different UNIX systems. In order to use these systems, you must first obtain an ITS user number. Students normally get an individually funded (IF) user number. This IF number can be validated to access any or all ITS systems. If you already have an IF account you may still need to have it validated for one of the ITS UNIX systems. For more information on getting a new IF number or adding validations to your IF number, please see: http://www.utexas.edu/cc/account
Other departments may also provide access to UNIX systems, in order to use these systems you will need to contact the specific department for more information on obtaining access to their systems.
An operating system manages the use of hardware resources, the storage and recall of data, controls the flow of data, and provides an environment for application programs. The UNIX operating system offers an interactive, multi-user, multitasking environment for users and provides for the creation and management of processes, the file system, and communications.
UNIX can be installed and used on many different types of computers. The UNIX operating system can be used on a CRAY supercomputer or on a microcomputer in your home. The beauty of UNIX is its portability and consistency across many different platforms.
Because UNIX runs on many different platforms, there are many variations of the operating system. The two major variations are AT&T System V and Berkeley Standard Distribution (BSD). Although they have many similarities, they also have their differences. The table below provides brief information about the ITS UNIX systems. For more information about each individual system, please see: http://www.utexas.edu/cc/unix/.
ITS UNIX Timesharing Systems
System Name |
Computer Name/Address |
Version of UNIX |
CCWF UNIX System (CCWF) |
ccwf.cc.utexas.edu |
Solaris |
UNIX Timesharing System (UTS) |
uts.cc.utexas.edu |
Digital UNIX |
Academic Data Server (ADS) |
spice.cc.utexas.edu |
AIX |
UNIX may be used for many different types of computing activities. It may be used to develop your own programs, to access many academic tools, or communicate with users on other systems. A list of commonly used UNIX applications is provided below.
Task |
Description |
Application |
Mail |
Each UNIX system provides you with an email
address. This account is separate and
unrelated to the University Mailbox System.
Your email address is: username@machinename So, the user pcarter on the ccwf system would have
an email address of pcarter@ccwf.cc.utexas.edu |
pine elm |
World
Wide Web |
All ITS UNIX systems have Web browsers installed. |
Netscape (Requires use of X-Windows) Lynx |
Editors |
Editors are used to create and/or edit text
files. You may use an editor to
compose a letter, make a list of things to do, or to write source code for
C++, HTML, PERL etc…. |
vi emacs pico |
USENET/Newsgroups |
USENET
is a collection of electronic discussion forums available via the
Internet. You may access the USENET
newsgroups via your UNIX account.
This will allow you to read and post messages to discussion groups. |
tin trn pine |
Statistics/Higher
Mathematics |
Many
faculty, staff , and students need access to applications for specific
academic and research purposes. Our
UNIX systems provide access to a variety of different software applications. |
Maple SAS IMSL SPSS Ingres |
File
Transfer |
You
may transfer files between your UNIX account and other network connected
systems, such as your home or office computer (if the machines are connected
to the Internet). |
Kermit ftp |
Program
Compilers/ Scripting
Languages |
Our
UNIX systems offer access to a number of compilers and scripting
languages. You may write your own
programs and or scripts. |
C++ FORTRAN C Pascal |
Text
Processing |
We
also provide access to a number of text formatting and typsetting tools. |
Troff TeX LaTeX |
The most basic operations you will perform on any UNIX system are logging in and logging out. This section discusses these operations and good password maintenance.
The first time you log in on any of the ITS UNIX systems, you must use your original username and password. For most users this means using their original IF number and password. If you no longer remember your original user number and password, you may contact the ITS Help Desk in VRC.
At the login: prompt, type the 7-character user number (in lower case). Press the <RETURN> key.
login: ifaa123
You are then prompted for your password as follows:
Password:
Type the password issued to you with your user number then press the <RETURN> key.
Your password will not be displayed. UNIX is case sensitive so type lower case and upper case characters accordingly.
If this is the first time you have logged in, a special new user program is run. This program may prompt you to type a new log in name that you will use for future logins. If you are not asked for a log in name, your user number will continue to be your log in name. If you are asked to select a new log in name, choose up to 8 lowercase letters that help others to identify you. Often, the first initial and last name are chosen as the log in name. If someone else has already used your choice of log in name, your log in name will not be accepted and you will have to choose another character combination.
Next, the program prompts you for optional data you may wish to include in the "personal information block". The personal information block provides an on-line database that other users may access using the finger command. You may include your real name, address, phone number and projects you are working on. If you do not wish to include any or all of the information, press <RETURN> to move to the next line. On-line instructions are provided as you work through the personal information block. If you want to exit from the program entirely, type <CTRL–C. You will be instructed to log in again after a 20 minute wait.
Subsequent logins to the UNIX systems will only prompt you for your log in name and your password. Following a successful log in, you will see the following information displayed:
the time and date of your last log in.
the message of the day, provided by the ITS UNIX staff, contains important information about the system - ALWAYS READ IT!
notification of new mail.
the command prompt.
The command prompt for ITS UNIX machines is usually the hostname (the name of the computer) followed by the % character.
Passwords should be changed on a periodic basis to protect your files and your user number. To change a password, type the following command at the command prompt:
% passwd
You will be prompted first for your current password, then twice for a new password ( the second prompt provides verification). In subsequent log ins your old password will not be accepted.
All passwords used on the ITS machines are checked to reduce the possibility of someone guessing your password. This measure helps to ensure the security of your data. The password program rejects passwords that match any information you entered into the personal database (for example: nicknames). The password program used at ITS is unique to ITS machines. Other systems may have similar programs, but this is not a standard UNIX feature.
When selecting a password, the following guidelines should be followed:
choose a password that is meaningful only to you, something that will not be easily guessed.
use 6 to 8 characters, or longer if permitted.
mixing case or inserting digits in the middle of your password makes it difficult for someone else to guess.
choose a password that you can remember.
do not choose your initials or nickname.
do not choose an ordinary word found in the dictionary, the UT password program will not accept it.
For an individually funded (IF) account you must go, in person, to the ITS Help Desk in VRC with the proper identification (valid UT ID) to have a new password assigned.
For a departmentally sponsored account, you must complete the following steps
1. Obtain a letter on department stationary signed by the account sponsor authorizing the change in password.
2. Take the letter to the ITS Accounting Office for verification of the sponsor's signature. The ITS accounting staff will initial the letter. The sponsor may appear in person without a letter.
3. Take the signed, initialed letter to the ITS Help Desk with proper identification (valid UT ID) to have a new password assigned.
For non - ITS systems, see your system administrator.
If you did not supply information in the first log in session, or if you want to add, delete or revise information, use the chfn command.
% chfn
The chfn command displays one line of the personal information at a time. To leave the information as it is, press <RETURN>. To change the information, type the new value and press <RETURN>. To leave an item blank, type none and press <RETURN>. After you have responded to all the prompts, chfn displays the message "Updating user information" and exits.
This personal information is used for the listing of a personal web page published from a ITS UNIX account.
Note: This option is not currently available on the CCWF system. To change your personal information on CCWF, you will need to send email remark@cc.utexas.edu or go to the Help Desk in VRC.
To end your session, type logout at the prompt.
% logout
A UNIX command is composed of a command name, options and arguments. The command name and its options and arguments must be separated by "white space". White space is defined to be any number of spaces or tabs.
%
commandname [options] [arguments]
[ ] indicate that this part of the command line is optional. The optional parts of a command line vary from one command to another and depend on the use of the command.
The commandname is always listed at the beginning of the command line.
An option changes the default behavior of a command. An option may give additional information or it may change the way in which the information is displayed. Options follow the command and usually begin with a "-" (the minus character).
An argument can be a filename, a directory name or a device name and is sometimes optional. Arguments are normally listed last on the command line. Some command lines may include several arguments.
In the examples below, the list files command, ls, is used with the -l option and various arguments.
List the files in the current directory:
% ls
List the files in the current directory in long format (the -l option has been added):
% ls -l
List the file named test.doc in long format (a specific argument has been added):
% ls -l test.doc
List the files named test.doc and unix.class in long format:
% ls -l test.doc unix.class
Multiple commands may be entered on the same line, but
the commands must be separated by semicolons.
Command lines may contain as many as 1024 characters. UNIX commands usually do not provide
notification of successful completion of a command; notification occurs only on an error.
The ls command is used to list the names of the files contained in a directory. To execute the ls command, type ls at the prompt.
% ls
The system responds with a list of files contained in your current directory. In the BSD version of UNIX the default is to list files in the ASCII alphabetic order.
Exercise:
1. Use the ls command to display the files in your working directory.
A file is a collection of related data. A file might contain a mail message that you have composed or an executable program. Every file must have a name.
Filenames in most versions of UNIX can contain up to 255 characters, but older versions may limit the length of a filename to 14 characters. General rules for composing filenames are listed below.
Case sensitive.
All characters are allowed except the / character.
Not all characters are good choices.
Recommended characters:
- letters (a-z and A-Z)
- numbers (0-9)
- period (.)
- underscore (_)
Examples of filenames:
chap1.1 TEXT.GROUP
short_course.1 UNIX_training
_materials_1.8.92
Saved.text.mss .login
By convention, certain suffixes indicate specific file types to some UNIX utilities. End file names with these characters only when you want to identify the files as follows:
File Extension |
File Type |
.c |
A file containing a C language source program |
.C |
A C++ source file |
.f |
A file containing a FORTRAN language source program |
.h |
A C language include file |
.o |
Object code (output from a compiler) |
.p |
A Pascal source file |
.Z |
A compressed file |
.tex |
A TeX or LaTex source file |
.html |
A file containing html source code |
.perl |
A file containing a perl source code |
.cgi |
Common Gateway Interface script or program |
.gif |
Graphics file |
.jpg |
Graphics file |
Options are used with commands to select a specific command parameter. For example, an option used with the ls command may give additional information or it may change the way in which the information is displayed. The -l option used with the ls command lists the contents of a directory in long format.
% ls -l
The ls command has several additional options. The -rc option lists files in reverse order of creation date. Other options for the ls command are listed below:
-a |
List all hidden files, those filenames that begin with a . (period) |
-R |
Lists entries recursively, includes current directory and all subdirectories. |
-l |
List in long format, includes file permissions, owner, size in bytes and time of last modification for each file. |
-F |
Lists files with a symbol used to denote file type (a / character following a file name denotes a directory file). |
-r |
Reverse the order of the sort, to reverse alphabetic order or reverse order of creation, as appropriate |
-t |
Sort by time modified |
Files beginning with a "." (the period character) are called hidden files. These files are used to configure your environment and to set the default behavior of various utilities and application programs. An example is the .login file which contains commands that are read and executed each time you log in. Another hidden file is the .mailrc file which is used to configure and change the default behavior of the mail program. Hidden files are not displayed by the ls command unless the -a option is used.
Exercise:
1. Use the ls command with each of the options listed above to display the contents of your working directory. Use the information displayed to answer the following questions:
Which file was modified last?
What is the name of the largest file?
2. Use the ls command with the -l option to list the following files:
test.doc unix.class neon students.doc
This sections covers the basic skills of creating and managing directories and basic file management.
The cat command (derived from concatenate - to connect in a series) is used to display the contents of text files. To use the cat command, type cat filename. The entire contents of filename will be displayed on your screen.
% cat unix.class
% cat unix.class test.doc
project_plan
1. Use the cat command to display the contents of the file named unix.class.
2. Execute the cat command only one time to display the contents of the files named test.doc, short_course.1 and project_plan.
The more command is used to display the contents of a file one screen at a time. The more command is very useful when viewing the contents of large files. To use the more command, type more filename. The notation ---More --- and a percentage of the file displayed is seen at the bottom of your screen.
% more test.doc
To advance to the next screen press the space bar.
To advance only one line, press the <Return> key.
To exit the more command, type q.
The more command has an entire control language that can be used while displaying any file. Listed below are the most common control keystrokes used with the more command.
Keystroke |
Action |
<Return> |
Display next line of text |
d |
Scroll forward lines [11] lines (Default is 11 lines.) |
f |
Scroll forward one screenful |
b |
Scroll back one screenful |
<interrupt> |
Quit |
q |
Exit from more |
<space bar> |
Next screenful of text |
h or ? |
Access the on-line help information |
Exercise:
1. Use the more command to control the display of the file named test.doc.
2. Execute the more command only one time to display the contents of the files named test.doc, short_course.1 and project_plan.
3. View the contents of the files listed in step 2 by using both the space bar and the <Return> key to advance the screen output.
4. Use each of the keystrokes listed above while displaying the contents of the files named test.doc and unix.class.
A directory is a file that contains information that is used by the system to find other files. When you log in to a UNIX machine you are automatically placed in a directory called your home or login directory. The home directory is created for you when you set up a computer account with ITS. This directory can be used to organize your files.
The directory that you are using is referred to as your working directory. When you first log in, your login directory and your working directory are the same. If you move to another directory using the appropriate commands, the new directory becomes your working directory.
A directory that is beneath another directory is referred to as a subdirectory. You can create or delete subdirectories from your home directory as needed. The directory above a subdirectory is called the parent directory of the subdirectory.
The UNIX file system organizes directories in a hierarchical structure. The structure can be described as an inverted tree with the top level called the root. The root is always signified by the initial / character. A set of directories and files make up the second level and another set of directories and files make up a third level and so on. Below is a figure that shows a hierarchical directory structure.
To change directories, use the cd command. For example, to move into the subdirectory called bin (in your home directory), type cd bin.
% cd bin
In the UNIX operating system, a naming convention has been established to easily identify your current directory and its parent directory. A single period or dot (.) refers to the current directory. Two periods or dots (..) refer to its parent directory. The command cd .. moves up one level in the directory hierarchy.
% cd ..
To go to the root directory, type cd /.
% cd /
To return to your home directory from any location, type cd.
% cd
1. Change from your home directory into the subdirectory named bin.
2. Move back up to the parent directory using the cd .. command.
3. Move to the root directory using the cd / command.
4. Move back to your home directory using the cd command.
To determine the directory where you are currently located, use the pwd (print working directory) command. UNIX responds with the pathname of your current directory location. The pathname specified by the pwd command lists your location in relationship to the root and lists each directory that is in the path from the root to your current location. Each directory is separated from the next by the / character.
% pwd
/home/ccwf/u0/cc/username
1. Use the pwd command to determine your current directory.
Each file and directory has a pathname that uniquely identifies that specific file. Anywhere you can use an ordinary file name, a pathname can be used. A pathname that specifies the path from the root to your working directory is called an absolute pathname. An absolute pathname is always read and written left to right, with the root (designated by the / character) always starting the pathname. The other type of pathname is a relative pathname. A relative pathname specifies the name of a file or the path to a directory starting at your current working directory. A relative pathname never begins with /.
Absolute pathname: /home/ccwf/u0/cc/username
Relative pathname: bin/email.course
Because pathnames are unique, it is possible to have two directories or files with the same name in two different directories. It is not possible to have two directories or files with the same name in the same directory.
Exercise:
1. List the absolute pathname for your current working directory.
2. List the relative path to the bin directory located one level under your home directory.
3. Find two directories named bin. List the pathnames for each on the lines provided below.
Directories can be created using the mkdir command. As you increase the number of files that you use, you will find directories can be very useful in organizing and maintaining your files. To create a new directory, type mkdir directoryname where directoryname is the name of the new directory.
% mkdir research
Exercise:
1. Create the following directories using the mkdir command.
research
programs documents book
correspondence
The cp command is used to copy files. When modifying a file, you may wish to make a copy of the file to keep as a backup. The cp command creates a new copy of the existing file and leaves the original file intact. To copy a file, type
cp sourcefile destinationfile
cp unix.class training.unix
Exercise:
1. Use the cp command to copy unix.class to a new file named training.unix.
2. Copy the file named chap1.1 to a new file named book_review.
3. Copy the file named roast to a new file named beef.
Files can be copied from one directory to another using the cp command. Copying files to another directory uses the exact same command syntax that copying a file uses. However, to successfully copy files to another directory, you must specify the correct pathname to the new directory. If you are copying a file not contained in your current working directory, you must be certain to specify the correct pathname for the source file.
% cp saved.text.mss documents
Exercise:
1. Copy the following files to the directory named documents.
chap1.1 saved.text.mss
2. Copy the following files to the directory named book.
text.group students.doc
To rename or move a file, type
mv sourcefile destinationfile
When using the mv command, only one copy of the file will exist both before and after execution of the command. If you move a file to a different directory that contains a file with the same name, the new file writes over the contents of the old file.
% mv project_plan train_project
% mv Text.Group bin
1. Use the mv command to rename project_plan to train_project.
2. Rename the file called text.group to Text.Group.
3. Rename the file named UNIX_training_materials_1.8.92 to training_1.27.92.
4. Move the file named chap1.1 to the research directory.
5. Move the file named Text.Group to the bin directory.
The rm command (abbreviated from remove) is used to remove files. To delete a file, type rm filename. When used alone, the rm command will delete files without any confirmation from you.. If you use the -i option when issuing the rm command, a confirmation of the removal is required. Respond with a y for yes or a n for no.
% rm -i training.unix
% rm: remove training.unix?
% rm -i
bin/Text.Group
% rm:
remove bin/Text.Group?
When a directory is no longer useful, it can be deleted using the rmdir command. A directory cannot be removed with the rmdir command unless it contains no files. To delete a directory, type rmdir directoryname.
% rmdir research
Files can be created by many different software packages. One of the easiest ways to create files is to a screen editor such as pico, vi, or emacs.
The pico editor has a very helpful interface. To edit a file using pico, type:
pico filename
Pico will start with a window similar to the one displayed below:
The following table, summarizes some useful commands for using the pico editor.
<Control -f> |
move Forward a character |
<Control -b> |
move Backward a character |
<Control -p> |
move to the Previous line |
<Control -n> |
move to the Next line |
<Control -a> |
move to the beginning of the current line. |
<Control -e> |
move to the End of the current line. |
<Control -v> |
Moves the window forward one full screen (provides a few lines of overlap for continuity) |
<Control -y> |
Moves the screen backward one full screen |
<Control -g> |
Get more help on pico commands |
<Control -o> |
Save the file without exiting pico |
<Control -x> |
Exit and save the file |
To use pico to edit the file test.doc, you would type:
% pico test.doc
Once your editing changes have been made, you may exit pico by typing, <Control-x>. You are then given the option to save the file or to simply exit.
Exercise:
1. Start pico using the file named short_course.1.
2. Practice moving the cursor location using the arrow keys.
3. Practice moving around the screen using the keystrokes listed above.
4. Add the following text to the beginning of the file.
Discretion is the better part of
valor. It takes two to make a quarrel.
5. Add the following text to the end of the file.
Many a true word is spoken in jest. It's never to late to learn.
6. Delete the lines containing stars at the beginning of the file.
The vi (pronounced vee-eye) text editor is a display editor. You can use vi to create new files or to change existing files. To start vi, type vi and the filename at the prompt.
% vi text.doc
When you start the vi program, the screen looks similar to the example below.
~
~
~
~"text.doc" [New file]
The cursor is always located in the upper left hand position of the screen. This is the beginning of your file.
The table below lists some of the most common commands used to move the cursor when you are not in insert mode.
h |
Moves the cursor to the left |
j |
Moves the cursor down |
k |
Moves the cursor up |
l |
Moves the cursor to the right |
<Control -d> |
Moves the window down half a screenful |
<Control -u> |
Moves the window up half a screenful |
<Control -f> |
Moves the window forward one full screen (provides a few lines of overlap for continuity) |
<Control -b> |
Moves the screen backward one full screen |
You can insert and delete text using the keystrokes listed in the table below.
i |
insert text immediately before the cursor |
a |
insert text immediately after the cursor |
o |
Open new line below the current line and enter insert mode |
O |
Open new line above the current line and enter insert mode |
Esc |
End insert mode |
A |
Append to end of line |
x |
Delete character |
dd |
Delete the line that contains the cursor |
dw |
Delete from the cursor through the end of the word |
4dw |
Deletes 4 words |
You can save changes to a file and quit vi using the commands listed in the table below.
ZZ |
Exit vi and save changes |
:wq |
Quit and save changes |
:q! |
Quit without saving changes |
:w filename |
Writes the new version of your file to "filename", leaves the original file untouched and keeps you in vi |
The lpr command (lpr is an abbreviation for lineprinter.) is used to send a copy of your file to a printer. The option -P is used to name a print site which follows the option. To use the lpr command, type lpr, space, -P, the print site, space and the filename.
% lpr -Ptay_lw test.doc
For a complete list of print sites available, type man sites at the prompt.
% man sites
If your file is a PostScript file (produced by troff, TeX or LaTeX text formatters), it will not print accurately on a lineprinter. A PostScript file has %! as its first two characters and contains formatting instructions that cannot be interpreted by a lineprinter. PostScript files should be sent to a laser printer (output sites for Laser Writers end with an lw). For more information about printing PostScript output files, see the man pages (man lpr).
At each output location, output is filed according to the last three digits of the ITS user number.
There are many resources available to help with your UNIX questions. These resources include man pages, printed documentation, frequently asked questions (FAQs) on gopher, and consulting services.
The on-line documentation or help system in the UNIX operating system is known as the "man" pages or manual pages. The man command is used to view the on-line documentation. Each man page is divided into the sections described below.
Name A short description of the command.
Synopsis A synopsis of the command's syntax.
Description A description of what the command does.
Options A list and description of options that can be used with the command.
Files A list of the files used or created when the command is executed.
See Also A list of relevant commands or files.
Bugs A list of known bugs and limitations.
As with most of the commands used in UNIX, the ls command has several options that are available to you. To view the options available for the ls command, type man ls.
% man ls
A complete description of the ls command and its
available options are displayed.
Exercise:
1. Use the man command to look up the on-line documentation on the ls command. Use the information listed in the man pages to answer the question below.
List two options that can be used with the ls command.
2. Using the man pages, look up the more command. What is the purpose of the more command?
The man pages are available for most UNIX commands and are organized into sections by function. Below is a list of each section and the functions contained.
Section |
Description |
1 |
General user commands |
2 |
System calls and system errors |
3 |
Library routines (C and FORTRAN) |
4 |
Special files and device drivers |
5 |
File formats (No intro man page) |
6 |
Games (No intro man page) |
7 |
Miscellaneous information pages |
8 |
System maintenance commands |
The man command searches the sections in the order 1, 6, 8, 2, 3, 4, 5, 7 and displays the first man page found.
Section 7 is used at the ITS for UT specific information or for information that does not fit in any other section.
To use the man pages to look up a specific section, type man sectionnumber and the command or term.
% man 7 sites
Exercise:
1. Use the man pages to look up information in section 7 pertaining to print sites.
To print a man page, type the following command. Insert the appropriate topic and print site where indicated.
% man topic | ul -t dumb | col -b | lpr -Psite
Note: Some
of the man pages found on the ITS machines are specific to UT Austin ITS
machines. Manual pages may be different
or may not be installed on non-ITS machines.
When you are uncertain of the specific term or command name to use to search the man pages, you can use the apropos command . The apropos command performs a case "insensitive" string search for a given string of characters. This is one of the few UNIX commands where case is not significant. An example of the apropos command is shown below.
% apropos print
The apropos command is the same as the man -k command, so the following gives exactly the same results.
% man -k print
Exercise:
1. Use the apropos command to find any man page references to the topic "print".
2. Use the apropos command to find any man page references to the topic "Pascal".