Unix Basics Imp
Unix Basics Imp
Table of Contents
Introduction.............................................................................................. 4
Font Conventions .............................................................................................. 4
Listing Files ............................................................................................................16 Copying Files ..........................................................................................................17 Renaming Files .......................................................................................................17 Deleting Files ..........................................................................................................18 Creating Links Between Files.................................................................................18 Printing Files...........................................................................................................19
Directories...............................................................................................19
About UNIX Directories.........................................................................................19 Displaying Directories ............................................................................................20 Changing Directories ..............................................................................................21 Moving Files Between Directories .........................................................................21 Copying Files to Other Directories .........................................................................22 Renaming Directories .............................................................................................22 Removing Directories .............................................................................................22
Introduction
This document is only a brief introduction to UNIX and does not include information on how to use all of its capabilities. Since this introduction to UNIX is brief, we encourage you to seek out more detailed introductory information. Information Technology offers free Short Courses on UNIX that you can sign up for. Fondren Library has a number of very good introductory books on UNIX available for checkout. These books go into more detail and cover more of the operating system than will be covered in this document. You can also purchase some introductory UNIX books at the Rice Campus Store or almost any local bookstore with a computing section. This document introduces you to the basics of UNIX, including: How to get started Shell and Commands File structures Directories
There are several variants of UNIX on the Rice campus; the type used most on Information Technology supported networks is from Sun Microsystems. Therefore, although the information concerning the UNIX operating system presented here is not limited to Sun workstations, it will focus on them. Information Technology maintains groups of machines for different groups of users; these groups of machines are known as domains. The major Information Technology domains are Owlnet, the Rice UNIX Facility (RUF), and Information Technology administration. Other departments or divisions may have their own domains, such as Computer Science or Electrical and Computer Engineering. Accounts in one domain are not valid on machines of other domains. Every workstation is labeled with its name and domain. If you have an Owlnet account, use the workstations or terminals in A121 or B223 Abercrombie, 241 Mechanical Engineering, 102 Ryon Lab, 105 Mudd, 221 Physics, or the workstations at your residential college.
Font Conventions
This document uses the true type font setting to represent any feedback echoed on the computer screen after you type a command. When you are told to type a command, this command will be printed in Times Roman font. this is the true type font.
What is UNIX?
UNIX is a powerful computer operating system originally developed at AT&T Bell Laboratories. It is very popular among the scientific, engineering, and academic communities due to its multi-user and multi-tasking environment, flexibility and portability, electronic mail and networking capabilities, and the numerous programming, text processing and scientific utilities available. It has also gained widespread acceptance in government and business. Over the years, two major forms (with several vendors variants of each) of UNIX have evolved: AT&T UNIX System V and the Univer-
UNIX Layers
sity of California at Berkeleys Berkeley Software Distribution (BSD). This document will be based on the SunOS 4.1.3_U1, Suns combination of BSD UNIX (BSD versions 4.2 and 4.3) and System V because it is the primary version of UNIX available at Rice. Also available are Solaris, a System Vbased version, and IRIX, used by Silicon Graphics machines.
UNIX Layers
When you use UNIX, several layers of interaction are occurring between the computer hardware and you. The rst layer is the kernel, which runs on the actual machine hardware and manages all interaction with the hardware. All applications and commands in UNIX interact with the kernel, rather than the hardware directly, and they make up the second layer. On top of the applications and commands is the command-interpreter program, the shell, which manages the interaction between you, your applications, and the available UNIX commands. Most UNIX commands are separate programs, distinct from the kernel. A nal layer, which may or may not be present on your system, is a windowing system such as X. The windowing system usually interacts with the shell, but it can also interact directly with applications. The nal layer is you, the user. You will interact with the entire operating system through just the shell, or through a combination of the shell and the window system. The gure below gives a visual representation of the layers of UNIX. You
Windowing System
FIGURE 1.
UNIX Layers
TTY Terminal
If you are using a TTY terminal (a TTY is line-at-a-time oriented as opposed to page oriented) and the screen is blank, you only need to press RETURN and a login prompt should appear on the screen.
Workstation
If the display features a box in the center of the screen with text similar to that in the gure below, then you are using a workstation that is congured to run a windowing system called the X Window system. These machines are called X terminals. (For more information on the X Window system, see the Information Technology document, UNIX 2, Introduction to the X Window System.).
If the screen is entirely black, then a screen-saving program is running automatically to protect the monitor from damage. Moving the mouse or pressing the RETURN key should wake up the display. (If you see the words This screen has been locked... then someone else is using the workstation, but they are temporarily away from their seat. Look for an unoccupied machine.) Move the mouse until the cursor (a black X) is on top of the white box.
Logging Out
Workstations and TTY Terminals
To end a work session, you must explicitly log out of a UNIX session. To do this, type logout at the command prompt. Once you have logged out, the system will either display the login prompt again or begin executing a screen saver program. You should never turn a workstation off. Turning off a terminal does not necessarily log you out. If you are having trouble logging out, see the section, Troubleshooting.
X Terminals
To log out of the X Window system from an X terminal, move the cursor into the console window (it is labeled console), type the command exit, and press RETURN. If you try to use the logout command in the console window, you will receive the message, Not in login shell.
It must be at least seven characters long. It must not match anything in your UNIX account information, such as your login name, or an item from your account information data entry. It must not be found in the systems spelling dictionary unless a character other than the rst is capitalized. It must not have three or more consecutively repeated characters or words in the dictionary contained within it.
For example, changing your password from Kat899 (based on a dictionary word) to B00z00e (bad password) will look similar to the following example, except that the keystrokes for you old and new password will not be echoed on the screen. passwd current password: Kat899 New password (? for help): B00z00e New password (again): B00z00e Password changed for userid These are bad examples and will not work, so choose your OWN password. Here is a good technique to follow for creating your password: All she wants to do is dance => Aswtdid On many systems, the password change does not take effect immediately, even though you have nished with the passwd command. It can take upwards of an hour for the system to install the new password, due to the scheduling of the password changing process. Thus you should be prepared to use your old password to login again shortly after changing it. If you should ever forget your password, you can go to the Information Desk in 103 Mudd Lab and request that a new password be generated for you. You will need to bring your Rice ID card with you to identify yourself.
UNIX Commands
The UNIX Shell
Once you are logged in, you are ready to start using UNIX. As mentioned earlier, you interact with the system through a command interpreter program called the shell. Most UNIX systems have two different shells, although you will only use one or the other almost all of the time. The shell you will nd on Information Technology supported networks is the C shell. It is called the C shell because it has syntax and constructs similar to those in the C programming language. The C shell command prompt often includes the name of the computer that you are using and usually ends with a special character, most often the percent sign (%). Another common shell is the Bourne shell, named for its author. The default prompt for the Bourne shell is the dollar sign ($). (If the prompt is neither one of these, a quick way to check which shell you are using is to type the C shell command alias; if a list appears, then you are using the C shell; if the message, Command not found appears, then you are using the Bourne shell). Modied versions of these shells are also available. TC shell (tcsh) is C shell with le name completion and command line editing (default prompt: >). The GNU Bourne-Again shell (bash) is basically the Bourne shell with the same features added (default prompt: bash$). In addition to processing your command requests, UNIX shells have their own syntax and control constructs. You can use these shell commands to make your processing more efcient, or to automate repetitive tasks. You can even store a sequence of shell commands in a le, called a shell script, and run it just like an ordinary program. Writing shell scripts is a topic discussed in the class notes for the UNIX IIIScripts Short Course.
UNIX commands are case-sensitive, but most are lowercase. UNIX commands can only be entered at the shell prompt. UNIX command lines must end with a RETURN. UNIX options often begin with a - (minus sign). More than one option can be included with many commands.
10
Case Sensitivity
man command-name The man pages provide an in-depth description of command-name, with an explanation of its options, examples, and further references. The information is an electronic duplicate of the paper reference manual pages. Use the man command for explicit information about how to use a particular command. Use the -k option to search for a keyword among the one line descriptions in the help les. man -k keyword The command apropos serves exactly the same function as man -k and is used in the same way. You can read about the man command itself using man. Type man man at the prompt. The UNIX reference manual is divided into eight numbered sections:
1. 2. 3. 4. 5. 6. 7. 8.
General User Commands System Calls User-level Library Functions Device Drivers, Protocols File Formats Games (rarely available) Document Preparation System Administration
You can see the command summary for each section by typing: man # intro where # is one of the eight section numbers. In addition, other applications that reside on your system may have man pages. These pages can often be called up in the same manner as the operating system man pages.
Case Sensitivity
UNIX is a case sensitive operating system. It treats lower-case characters differently than upper-case characters. For example, the les readme, Readme, and README would be treated as three different les. Most command names and les are entirely in lower-case. Therefore, you should generally plan to type in lower-case for most commands, command line arguments, and option letters.
11
down the SHIFT key and press the c key to generate a capital C). The notation for control characters is usually ^C or CTRL-C. Some standard special keys and control characters are summarized below.
TABLE 1. Special
BACKSPACE
12
display or set the date display information about users display information about processes display or change current environment C shell command to set shell variables C shell command to dene command abbreviations C shell command to display recent commands
Editing Tools
Command pico vi diff grep sort wc look awk gnuemacs Purpose simple text editor screen oriented (visual) display editor show differences between the contents of les search a le for a pattern sort and collate lines of a le (only works on one le at a time) count lines, words, and characters in a le look up specied words in the system dictionary pattern scanning and processing language advanced text editor
13
14
Creating Files
Many les are created using a text editor. A text editor is a program that allows you to enter and save text. You can also use a text editor to manipulate saved text through corrections, deletions, or insertions. The main text editors on Information Technology managed networks are vi, GNU Emacs, Pico, and aXe. (Note: vi is included with every UNIX system, but GNU Emacs is commonly installed separately by system managers. aXe is only available if you are using the X Window system.) You should learn how to use at least one of these tools. Information Technology has tutorial documents on each of these editors. Please see the section, Additional Resources, for information on the tutorials. You can create a le without a text editor by using the cat command (short for concatenate) and the > (redirect output) symbol. To create a le using the cat command, type: cat > new-lename
15
Displaying Files
where new-lename is the name you wish to give the le. The command cat generally reads in a le and displays it to standard output. When there is no lename directly following the command, cat treats standard input as a le. The > symbol will redirect the output from cat into the new lename you specify. cat will keep reading and writing each line you type until it encounters an endof-le character. By typing CTRL-D on a line by itself, you generate an end-of-le character. It will stop when it sees this character. Try it, using this example as a guide: cat > practice When you reach the end of each line, press the RETURN key. You can only correct mistakes on the line you are currently typing. Use the DELETE key to move the cursor back to the mistake and then retype the rest of the line correctly. When you have completed the last line, press RETURN and type CTRL-D.
Displaying Files
Now that you have created a le, you can display it one of several ways. You could use the cat command. Just type cat followed by the name of the le that you want to see. cat practice Sometimes the les you want to view are very long. When using the cat command, the text will scroll by very quickly. You can control the ow of text by using CTRL-S and CTRL-Q. CTRL-S stops the ow of text and CTRL-Q restarts it. If you use CTRL-S, stopping the ow of text, and so on, you must remember to type CTRL-Q or the computer will not display any output, including anything that you type. more is a program that displays only one screen of information at a time; it waits for you to tell it to continue. Type more followed by a lename. more practice The computer will display one screen of text and then wait for you to press the space bar before it displays the next page of text, until you reach the end of the le. Pressing the ? character will show help for more. A utility of greater power called less is available on many systems; it allows reverse scrolling of les and other enhancements. It is invoked the same way as more.
Listing Files
The ls command will list the les in the current directory that do not begin with a period. Below is a list of options you can tack on to ls: ls -a ls -l ls -s lists all the contents of the current directory, including les with initial periods, which are not usually listed. lists the contents of the current directory in long format, including le permissions, size, and date information. lists contents and le sizes in kilobytes of the current directory.
16
Copying Files
If you have many les, your directory list might be longer than one screen. You can use the programs more or most with the | (vertical bar or pipe) symbol to pipe the directory list generated as output by the ls command into the more program. more or less will display the output from ls one page at a time. ls | more
Copying Files
To make a copy of a le, use the cp (copy) command. cp lename newlename where lename is the le you wish to copy and newlename is the le you are creating. cp practice sample (make a copy of practice called sample) ls practice sample The example created a new le called sample that has the same contents as practice. If sample already exists, the cp command will overwrite the previous contents. New accounts are often set up so that cp will prompt for conrmation before it overwrites an existing le. If your account is not set up in this manner, use the -i option (cp -i) to get the conrmation prompt, like so: cp -i practice sample
Renaming Files
To rename one of your les, use the mv (move) command. mv oldlename newlename where oldlename is the original lename and newlename is the new lename. For instance, to rename sample as workle type: mv sample workle ls practice workfile This moves the contents of sample into the new le workle. (Note: Moving a le into an existing le overwrites the data in the existing le.) New accounts are often set up so that mv will prompt for conrmation before doing this. If your account is not set up in this manner, use the -i option (mv -i) to get the conrmation prompt.
17
Deleting Files
Deleting Files
To delete les, use the rm (remove) command. For instance, to delete workle, type: rm workle ls practice Important: rm can be very dangerous. Once a le has been removed you cannot get it back, except, possibly, from system backups (which may or may not contain the le). It may take the system administrators several days to recover your deleted le, so use a great deal of caution when deleting les. New accounts are often set up so that rm will prompt for conrmation. If your account is not set up in this manner, use the -i option to get the conrmation prompt.
18
Printing Files
Printing Files
NOTE: Line printers are used for text-only les. Laser printers are needed to handle graphics or PostScript les. PostScript is a page-description language developed by Adobe Systems, Inc. and was specially designed for creating graphics and typography on a printed page. The option ag -P printername species which laser printer to use and is optional (as indicated by the brackets). When no printer is given, the print command uses the system default printer. However, on some systems such as Owlnet, you must always specify a laser printer with the -P ag. For more information on printing commands, use the man command to consult the manual pages on lpq, lpr, and lprm. To print a le, use the lpr command: lpr lename or lpr [-Pprintername] lename (for laser printers only) To get a list of the printers available to your machine, type: lprloc lprloc lists all of the printers that your system knows about, by name, along with their type and location. To get some status information on the printers, use the command lpstat -p. Printer accounting information is available by running the command pacinfo.
Directories
About UNIX Directories
UNIX directories are similar to regular les; they both have names and both contain information. Directories, however, contain other les and directories. Many of the same rules and commands that apply to les also apply to directories. All les and directories in the UNIX system are stored in a hierarchical tree structure. Envision it as an upside-down tree, as in the gure below.
bin lib
lib
file2
At the top of the tree is the root directory. Its directory name is simply / (a slash character). Below the root directory is a set of major subdirectories that usually include bin, dev, etc, lib, pub, tmp, and usr. For example, the /bin directory is a subdirectory, or child, of / (the root directory). The root directory, in this case, is also the parent directory of the bin directory. Each path leading down, away from the root, ends in a le or directory. Other paths can branch out from directories, but not from les.
19
Displaying Directories
Many directories on a UNIX system have traditional names and traditional contents. For example, directories named bin contain binary les, which are the executable command and application les. A lib directory contains library les, which are often collections of routines that can be included in programs by a compiler. dev contains device les, which are the software components of terminals, printers, disks, etc. tmp directories are for temporary storage, such as when a program creates a le for something and then deletes it when it is done. The etc directory is used for miscellaneous administrative les and commands. pub is for public les that anyone can use, and usr has traditionally been reserved for user directories, but on large systems it usually contains other bin, tmp, and lib directories. Your home directory is the directory that you start out from when you rst login. It is the top level directory of your account. Your home directory name is almost always the same as your userid. Every directory and le on the system has a path by which it is accessed, starting from the root directory. The path to the directory is called its pathname. You can refer to any point in the directory hierarchy in two different ways: using its full (or absolute) pathname or its relative pathname. The full pathname traces the absolute position of a le or directory back to the root directory, using slashes (/) to connect every point in the path. For example, in the gure above, the full pathname of le2 would be /usr/bin/le2. Relative pathnames begin with the current directory (also called the working directory, the one you are in). If /usr were your current directory, then the relative pathname for le2 would be bin/le2. If you are using C shell, TC shell, or the Bourne-Again shell, UNIX provides some abbreviations for a few special directories. The character ~ (tilde) refers to your home directory. The home directory of any user (including you, if you want) can be abbreviated from /parent-directories/userid to ~userid. Likewise, you can abbreviate /parent-directories/youruserid/le to ~/le. The current directory has the abbreviation . (period). The parent of the current directory uses .. (two consecutive periods) as its abbreviation.
Displaying Directories
When you initially log in, the UNIX system places you in your home directory. The pwd command will display the full pathname of the current directory you are in. pwd /home/userid By typing the ls -a command, you can see every le and directory in the current directory, regardless of whether it is your home directory. To display the contents of your home directory when it is not your current directory, enter the ls command followed by the full pathname of your home directory. ls /home/userid If you are using a shell other than the Bourne shell, instead of typing the full pathname for your directory, you can also use the tilde symbol with the ls command to display the contents of your home directory. ls ~
20
Changing Directories
To help you distinguish between les and directories in a listing, the ls command has a -F option, which appends a distinguishing mark to the entry name showing the kind of data it contains: no mark for regular les; / for directories; @ for links; * for executable programs: ls -F ~
Changing Directories
To change your current directory to another directory in the directory tree, use the cd command. For example, to move from your home directory to your projects directory, type: cd projects or, cd ~/projects (full pathname using ~) or, cd /home/userid/projects (full pathname) Using pwd will show you your new current directory. pwd /home/userid/projects To get back to the parent directory of projects, you can use the special .. directory abbreviation. cd pwd /home/userid If you get lost, issuing the cd command without any arguments will place you in your home directory. It is equivalent to cd ~, but also works in the Bourne shell. .. (relative pathname from home directory)
21
Renaming Directories
You can rename an existing directory with the mv command: mv oldDirectory newDirectory The new directory name must not exist before you use the command. The new directory need not be in the current directory. You can move a directory anywhere within a le system.
Removing Directories
To remove a directory, rst be sure that you are in the parent of that directory. Then use the command rmdir along with the directorys name. You cannot remove a directory with rmdir unless all the les and subdirectories contained in it have been erased. This prevents you from accidentally erasing important subdirectories. You could erase all the les in a directory by rst going to that directory (use cd) and then using rm to remove all the les in that directory. The quickest way to remove a directory and all of its les and subdirectories (and their contents) is to use the rm -r (for recursive) command along with the directorys name. For example, to empty and remove your projects directory, move to that directorys parent, then type: rm -r projects (remove the directory and its contents)
22
Removing Directories
read ( r )
A user who has read permission for a le may look at its contents or make a copy of it. For a directory, read permission enables a user to nd out what les are in that directory. A user who has write permission for a le can alter or remove the contents of that le. For a directory, the user can create and delete les in that directory. A user who has execute permission for a le can cause the contents of that le to be executed (provided that it is executable). For a directory, execute permission allows a user to change to that directory.
write ( w ) execute ( x )
For each le and directory, the read, write, and execute permissions may be set separately for each of the following classes of users: User ( u ) Group ( g ) Others ( o ) The user who owns the le or directory. Several users purposely lumped together so that they can share access to each other's les. The remainder of the authorized users of the system.
The primary command that displays information about les and directories is ls. The -l option will display the information in a long format. You can get information about a single UNIX le by using ls -l lename. Each le or subdirectory entry in a directory listing obtained with the -l option consists of seven elds: permission mode, link count, owner name, group name, le size in bytes, time of last modication, and the lename (the group name appears only if the g ag is also specied, as in ls -lg). The rst 10 characters make up the mode eld. If the rst character is a d then the item listed is a directory; if it is a - then the item is a le; if it is an l then it is a link to another le. Characters 2 through 4 refer to the owners permissions, characters 5 through 7 to the groups permissions (groups are dened by the system administrator), and the last three to the general publics permissions. (You can type id to verify your userid and group membership.) If a particular permission is set, the appropriate letter appears in the corresponding position; otherwise, a dash indicates that the permission is not given. The second eld in the output from ls -l is the number of links to the le. In most cases it is one, but other users may make links to your les, thus increasing the link count. A special warning to people using links to other peoples les: your copies of their les can be counted against them by the le quota system available on certain UNIX variants. That is why making links other than symbolic links to other peoples les is strongly discouraged. The third eld gives the userid of the owner of the le. The group name follows in the fourth eld (if the -g option is used in conjunction with -l). The next two elds give the size of the le (in bytes) and the date and time at which the le was last modied. The last eld gives the name of the le. ls -l myle -rw-r--r-- 1 owner 588 Jul 15 14:39 myfile A les owner can change any or all of the permissions with the chmod (change mode) command. The chmod command allows you to dictate the type of access permission that you want each le to have. In the previous example the current permissions for myle are read for everybody, write for the owner, and execute by no one. The arguments supplied to chmod are a symbolic specication of the changes required, followed by one or more lenames. The specication consists of whose permissions are to be changed: u for user (owner), g for group, o for others, or some combination thereof (a (all) has the same effect as ugo), how
23
Removing Directories
they are to be changed (+ adds a permission, - removes a permission, and = sets the specied permissions, removing the other ones) and which permission to add or remove (r for read, w for write, and x for execute). For example, to remove all the permissions from myle: chmod a-rwx myle ls -l myle ---------- 1 owner 588 Jul 15 14:41 myfile
(Note: chmod a= myle achieves the same effect.) To allow read and write permissions for all users: chmod ugo+rw myle ls -l myle -rw-rw-rw- 1 owner 588 Jul 15 14:42 myfile To remove write permission for your groups and other users: chmod go-w myle ls -l myle -rw-r--r-- 1 owner 588 Jul 15 14:42 myfile Finally, to allow only read permission to all users: chmod a=r myle ls -l myle -r--r--r-- 1 owner 58 Jul 15 14:43 myfile Now the le is protected by allowing only read access; it cannot be written to or executed by anyone, including you. Protecting a le against writing by its owner is a safeguard against accidental overwriting, although not against accidental deletion. chmod will also accept a permission setting expressed as a 3-digit octal number. To determine this octal number, you rst write a 1 if the permission is to be set and a 0 otherwise. This produces a binary number which can be converted into octal by grouping the digits in threes and replacing each group by the corresponding octal digit according to the table below.
TABLE 2. Symbolic
to Octal Conversions
Octal 0 1 2 3 4 5
Symbolic
24
Removing Directories
TABLE 2. Symbolic
to Octal Conversions
Octal 6 7
Symbolic
rwrwx
Thus, if the setting you want is rw-r--r--, determine the octal number with the following method:
This shows that the octal equivalent of rw-r--r-- is 644. The following example illustrates that the permissions for myle have been reset to the values with which we began. chmod 644 myle ls -l myle -rw-r--r-- 1 owner 588 Jul 15 14:44 myfile To change the permissions back to read only, you can execute chmod as follows: chmod 444 myle ls -l myle -r--r--r-- 1 owner 588 Jul 15 14:45 myfile As with les, directories may also have permissions assigned. When listing directories, you may use the -d option to keep from descending into the directories you list. Otherwise, the contents of the directories will be displayed as well as their names. Below is an example of permissions assigned to a directory: ls -lgd home drwxrwxr-x 1 owner caam223 588 Jul 15 9:45 home The directory and the les and directories under it may be read and executed by anyone, but written to only by the owner and users in the caam223 group. Assuming you are the owner of this directory, you may decide to change the permission to allow only yourself and the caam223 group to read and execute les in the home directory. You would set the permissions accordingly: chmod o-rx home ls -lgd home drwxrwx--- 1 owner caam223 588Jul 15 9:46 home You may decide that only you should be able to alter the contents of the directory. You must remove the write permission for the group. Introduction to the UNIX Operating System on IT Systems
25
Removing Directories
chmod 750 home ls -lgd home drwxr-x--- 1 owner caam223 588 Jul 15 9:48 home An alternative to the previous command is chmod g-w. When you create a le the system gives it a default set of permissions. These are controlled by the system administrator and will vary from installation to installation. If you would like to change the default which is in effect for you, choose your own with the umask command. Note that the permission specied by the umask setting will be applied to the le, unlike that specied in the chmod command, which normally only adds or deletes (few people use the = operator to chmod). First, issue the command without arguments to cause the current settings to be echoed as an octal number: umask 022 If you convert these digits to binary, you will obtain a bit pattern of 1s and 0s. A 1 indicates that the corresponding permission is to be turned off, a 0, that it is to be turned on. (Notice that the bit patterns for chmod and umask are reversed.) Hence, the mask output above is 000010010, which produces a permission setting of rwr-r- (i.e., write permission is turned off for group and other). Newly created les always have the execution bit turned off. Suppose you decide that the default setting you prefer is rwxr-x---. This corresponds to the masking bit pattern 000010111, so the required mask is 026: umask 26 Now, if you create a new le during this session, the permissions assigned to the le will be the ones allowed by the mask value.
Wildcard Characters
Using wildcard characters that allow you to copy, list, move, remove, etc. items with similar names is a great help in manipulating les and directories.
1. 2. 3.
The symbol ? will match any single character in that position in the le name. The symbol * will match zero or more characters in the name. Characters enclosed in brackets [and] will match any one of the given characters in the given position in the name. A consecutive sequence of characters can be designated by [char char].
?ab2 would match a name that starts with any single character and ends with ab2. ?ab? would match all names that begin and end with any character and have ab in between. ab* would match all names that start with ab, including ab itself. a*b would match all names that start with a and end with b, including ab. s[aqz] would match sa, sq, and sz. s[2-7] would match s2, s3, s4, s5, s6 and s7.
3.
26
These wildcard symbols help in dealing with groups of les, but you should remember that the instruction: rm * would erase all les in your current directory (although by default, you would be prompted to okay each deletion). The wildcard * should be used carefully.
Processes
Every command or program running under UNIX is called a process. A sequence of related processes is called a job. Your applications and even your shell itself are processes. The windowing system is also a process, or a collection of processes. The UNIX kernel manages the processes on the system, usually without distinguishing among them. UNIX is a multi-tasking systemit allows you to continue to work in the foreground while running one or more jobs in the background. It also runs the processes of many users simultaneously. You could even log off and come back later if the background jobs do not require interaction with you.
ps displays the process ID, under PID; the control terminal (if any), under TT; the state of the process, under STAT; the cpu time used by the process so far (including both user and system time), under TIME; and nally, an indication of the COMMAND that is running. The state of the process is indicated by a sequence of letters. The man pages for ps explain what the letters mean if you want to know. For most purposes, you wont really need to know what the letters mean.
27
28
Logging In
In the Bourne shell, the syntax is: nice +priorityNumber command argument The available priority numbers for users ranges from 1 to 19 with 19 being the lowest priority. In other words, the higher the nice value, the lower the processing priority. (Note: It is important to check the network policy for the required nice value for background jobs on your system; they are usually required to be niced and your job may be downgraded in priority if it was niced at the wrong value.) Set your command at the required nice value or higher. If you do not include a number argument, the value will default to 4 for the C shell and 10 for the Bourne shell. For example, if you wanted to run a long non-interactive job, and you didnt have to have the results of this job right away, you should run it in the background and set a high nice value. Using the C shell, you would type: nice -19 jobname &
Remote Login
Sometimes, while you are logged into one workstation, you will nd that you would like to be logged in to another workstation, le server, or other UNIX system. The command rlogin allows you to do so provided that you have an account on the other system. Type: rlogin newSystem You may then have to supply your password. You should also get the messages about logging in that are used on newSystem. If your userid is different on newSystem you will have to use the form: rlogin newSystem -l userid
Troubleshooting
Logging In
Problem: The system prints login incorrect. Check to make sure that you are typing your userid and password exactly as they appear on your information sheet (make sure youre using the proper case for all characters). If you still cannot log in, go to the Consulting Center in 103 Mudd Lab and ask for help. Problem: The computer types everything in upper-case with slashes in it. SAMPLE OF/WHAT/PROBLEM LOOKS LIKE Your userid was entered in uppercase letters, so the system thinks that your terminal can only understand uppercase letters. You need to type logout and then login again making sure that you enter your userid in lowercase letters only. (If the screen displays uppercase as you type your userid, you may
29
Logging Out
have to turn the CAPS key off by pressing it once and try logging in once more.)
Logging Out
If you experience difculty logging out, check to see if you are having one of the following problems. Do not turn off the workstation or terminal. This will not disconnect you from UNIX. Problem: The system replies There are stopped jobs when you try to log out. Type jobs to see what they are, then type kill %% to terminate all stopped background jobs. After that, try logging out again. Problem: The system replies, Not in login shell. First, type exit, press RETURN, and then type logout at the prompt, if necessary. Problem: Nothing seems to work and you cant log out. You might be stuck in a program or shell other than the login shell. Press RETURN to clear any previous commands; then try typing CTRL-C, q, :q, :q!, exit, CTRL-D, CTRL-Q, or CTRL-Z to get back into the login shell. Then try logout again. The following sequence might also work if your terminal is NOT connected directly to your real host machine. Press RETURN, then type ~. followed by RETURN. If you need additional help, go to the Consulting Center in 103 Mudd Lab during consulting hours or call 713-527-4983. You can also send electronic mail to the Consulting Center by using the address: problem@rice.edu, or better yet, use the web: http://problem.rice.edu/
Additional Resources
You now have enough information to get started using UNIX. To learn more about UNIX and specic applications, you can refer to a number of resources. You can use the man command to get online help. This is the quickest and easiest way to get help during a UNIX session. Virtually every UNIX operation and command has an entry. UNIX documentation written by the vendor for their workstations is available in the document racks of Information Technology maintained labs. Information Technology has a number of tutorial and reference documents available free of charge outside the Consulting Center in 103 Mudd Lab. Below are some of the UNIX-related documents. Introduction to the X Window System Customizing the X Window System Introduction to the vi Editor Introduction to the aXe Editor Introduction to GNU Emacs Compilers, Make, and Debuggers
30
Problems or Questions
Fondren Library has a full set of UNIX reference documentation as well as a large checkout collection of books and manuals on UNIX and other related topics, including some very good introductory books. The Rice Campus Store has introductory and advanced books on UNIX, as does any bookstore with a computer books section. Your professor may also have some course notes available at the Rice Campus Store. If you would prefer a hands-on tutorial introduction to UNIX, Information Technology offers free noncredit, one to three hour sessions on various computing topics, including an introduction to UNIX. Short Course calendars are available outside 103 Mudd Lab. For more information, call 713-348-4983 or on RiceInfo (URL: http://www.rice.edu).
Problems or Questions
Faculty, Staff, and Graduate Students:
If you have a problem, contact your computing support representative by sending an e-mail message to problem@rice.edu detailing your question. Your query is examined by a staff dispatcher for severity and assigned to the appropriate staff. This is the most effective communication method since computing support staff are often working in the eld and unreachable by phone. In addition, the dispatcher is aware of who is on vacation or out ill.
Undergraduates:
If you have a problem, contact your computing support representative by sending an e-mail message to problem@rice.edu detailing your question. Your query is automatically assigned to your College Computing Associate (CCA). If you need immediate assistance during normal business hours, you can call the Consulting Center at 713.348.4983. During the semester, the Consulting Center has limited evening and weekend hours as well. To report emergencies, which are urgent system-wide problems (i.e.: all Wiess' network connections are down or all the PCs in a lab are non-functional), contact the Operations Center at 713.348.4989. Staff work 24 hours a day, 365 day a year and can page appropriate administrators for major network or computing problems. More information is available at http://www.rice.edu/Computer/student.html
31