Beruflich Dokumente
Kultur Dokumente
UNIX
Copyright B. Brown, 1988-2000. All rights reserved. March 2000.
Devices
The UNIX operating system treats all devices as byte streams. To programs, devices look like files, and appear as filenames in the /dev sub-directory. Typical devices are
ds die ik rvs trias emnl pitr rnes /e/d dvhx /e/tx dvty /e/p dvlx
Hardware devices
Hardware devices appear as filenames in the /dev subdirectory.
uva.ulb.ac.be/cit_courseware/unix/unix15.htm 1/11
2/15/13
/e/osl dvcnoe /e/p.2 dvl0. /e/d.1 dvh0. /e/d0 dvwn /e/d.1 dvf0. /e/mm dvke /e/e dvmm /e/t0. dvty.. /e/tp. dvty0. /e/ul dvnl
sse cnoe ytm osl sse pitr ytm rnes hr dss ad ik hr ds cnrle ad ik otolr fop dss lpy ik kre mmr enl eoy sse mmr ytm eoy trias emnl ped trias suo emnl nl dvc ul eie
Exercise 1
Identify your ttyp number (by using who), and with a command syntax based on echo, send the current date to the terminal device. Enter the command you used to do this is the space provided below. _________________________________________________ What type of device is the ttyp device? Cross out that device which does not apply. block character
uva.ulb.ac.be/cit_courseware/unix/unix15.htm 2/11
2/15/13
Review 1: Devices
The two types of devices used by Unix systems are ________________________ _________________________ All devices appear as filenames under which subdirectory _________________________________________________ The filename associated with the system console device is _________________________________________________ What device name do you think is associated with the system line printer (hint: look in the /dev subdirectory)? _________________________________________________ Remote terminals are associated with the filenames _________________________________________________ The null device is different from other devices in that when data is written to it, the data _________________________________________________
TERMINALS
All users communicate with the Unix host via a terminal. The terminal type is displayed each time the user logs in, and can be altered to suit a wide variety of terminal types. Each terminal type uses a different set of command codes for cursor positioning and editing. By matching the physical terminal type with the software entry, the Unix system can use the appropriate software driver.
2/15/13
The Bourne shell uses the following entry to specify the terminal type. TERM=termtype; export TERM The terminal type is easily set within the shell by typing this at the command prompt. To make the change permanent, the entry in .profile must be edited.
disable disables a terminal or printer. enable enables a terminal or printer. lock locks a terminal using a password. Terminal remains locked till the password is re-entered. setcolor allows changing of screen attributes. May not work on all terminals (uses escape code sequences). setkey works only on the system console. Assigns a string to a function key. stty tabs tput tset tty sets options for terminals. sets tab stops on the users terminal. The terminal must support remotely-settable hardware tabs. queries the terminfo database for attributes related to the current terminal setting. used for setting erase and kill characters, setting or resetting delays, terminal types etc. prints the pathname of the users terminal on stdout.
Review 2: Terminals
Identify your terminal number _________________________________________________ Show how to change the terminal type to wyse30 using the Bourne shell. _________________________________________________
uva.ulb.ac.be/cit_courseware/unix/unix15.htm 4/11
2/15/13
What file holds all the terminal definitions? _________________________________________________ A user is going for morning tea but does not want to log off the system. They are worried that another user might try to gain access whilst they are not present. What should they do? _________________________________________________ _________________________________________________ How does the tabs command affect the terminals output? _________________________________________________ Which command would the system console operator use to assign keywords to function keys. _________________________________________________ The command setcolor does not work on my terminal? What is a possible cause? _________________________________________________ _________________________________________________
Using stty
This sets certain terminal I/O options for the device associated with stdin. When typed without arguments, it displays the current settings of these options. The format of the command is stty [-a] [-g] [options] The various options supported are parity character size baud rate stop bits flow control, cts, xon-xoff upper-lowercase translation cr/cr-lf translation, delays after cr/cr-lf, formfeed, tabs echo, full/half-duplex A - sign preceding an argument turns that option off. Some examples are, stty -echo ;suppress echoing of input
uva.ulb.ac.be/cit_courseware/unix/unix15.htm 5/11
2/15/13
stty erase # ;set erase character to # stty quit @ ;set SIGQUIT to @ (initially ctrl-\)
Using tput
This command uses the terminfo database to make the values of terminal dependent attributes available to the shell. The format of the command is tput -Ttermtype attribute Some examples are, tput clear ;echo clear screen sequence tput cols ;print the number of columns bold=`tput smso` norm=`tput rmso` echo "${bold}Hello there${norm}" The last example assigns the codes for bold-on and bold-off to shell variables. These are then used to highlight a text string.
Using tset
This command is used to specify the erase and kill characters for the terminal, as well as specifying the terminal type and exporting terminal information for use in the shell environment. This command is used at login time (.profile) to determine the terminal type. Examples of commands are, tset vt100 ;set terminal type to vt100 tset -e# ;set erase character to # (default ctrl-H) tset -k@ ;set kill character to @ (default ctrl-U)
uva.ulb.ac.be/cit_courseware/unix/unix15.htm
6/11
2/15/13
.......................................................... I am using an ansi terminal. Show two different commands I can use to set the terminal type. .......................................................... ..........................................................
csh
The C shell is an alternative to the Bourne shell, used in previous modules. This section explains the features and syntax of the C shell. The objective of this section is to familiarise the user with the common features of the C shell interface. This exposure should make the user more proficient in UNIX, extend the base of knowledge, and lead to greater productivity. Quick Overview The C Shell varies from the Bourne shell by providing
aiss lae hsoylss itr it ;iia t selvrals smlr o hl aibe ; ls o peiu cmad ue dfeetsna a it f rvos omns sd ifrn ytx
Note that the .login file is the C shell equivalent of the Bourne shell file .profile.
Typical commands placed in the .login file are set ignoreeof set mail=(/usr/spool/mail/username) The purpose of ignoreeof prevents the user from using ctrl-d to exit the shell; in this instance, the user must explicitly type the command exit.
uva.ulb.ac.be/cit_courseware/unix/unix15.htm 7/11
2/15/13
C Shell Variables
The set command assigns values to shell variables. The syntax is identical to that of the Bourne shell. set path=(. /bin /usr/bin /usr/local) The . indicates that the current directory is to be searched first. When commands are added, the rehash command is used to get the shell to recompute its internal table of commands.
Some of the variables are either set or unset; they have no specific value. One such example is the variable ignoreeof. The following commands turn it on (set) and turn it off (unset) respectively. set ignoreeof unset ignoreeof Type the following command to set ignoreeof. % set ignoreeof
Another handy variable is noclobber. When the shell redirects the output of a command using >, the file is created anew.
uva.ulb.ac.be/cit_courseware/unix/unix15.htm 8/11
2/15/13
Type the following command to set this variable % set noclobber The C shell will now not over-write existing files.
Type the following command % date > now Repeat the last command again. What happened? _________________________________________________ _________________________________________________
Now, type the command % date >! now What happened? _________________________________________________ _________________________________________________ In the second instance, using the >! redirection, no error message was displayed, and the file was created anew. This provides a means of deliberately over-riding the noclobber setting.
uva.ulb.ac.be/cit_courseware/unix/unix15.htm
2/15/13
! 2
Type the command history to view previously entered commands. % history What history command can you use to repeat the command 'date > now' _________________________________________________
uva.ulb.ac.be/cit_courseware/unix/unix15.htm
2/15/13
! ! ! d
uva.ulb.ac.be/cit_courseware/unix/unix15.htm
11/11