If you have any questions or suggestions concerning this courseware, please fill in the comments form or send email to b_brown@staff.cit.ac.nz. I'd love to hear from you. SYSTEM V SCO-UNIX Module 1: An Introduction to UNIX UNIX is an Operating System now available on the IBM-386. It was developed in the USA, originally by BELL, then licensed to AT&T. The Unix system used in this LAB is from Santa Cruz Operation (SCO), release system V. Access is provided to the UNIX host via the CIT wide network, and appropriate software connects the local computer to the provided UNIX hosts. The software is TELNET, a public domain package used to access remote UNIX hosts via Ethernet. _________________________________________________________________ LOGGING IN TO SCO UNIX Follow the appropriate instructions for your system to access the Unix server. SCO UNIX will currently be displaying the message National Center for Supercomputing Applications NCSA Telnet for the PC version 2.2 7/5/88 ALT-H presents a summary of special keys System V.3.2 UNIX (scosysv.sco.COM) Login : UNIX systems are case sensitive; upper and lower case characters are treated as different. All UNIX type systems generally use lowercase characters. All commands should be typed in lowercase characters. All users on a UNIX system are assigned their own usernames. When they logon to the system, they are placed in a HOME directory, which is a portion of the disk space reserved just for them. Type your allocated username. UNIX asks for your password. Type your allocated password. Note that the password is not displayed on the screen as you enter it. Login: Bloggs Password: UNIX checks the username and password you typed, and if correct, will run the shell program for you. The shell program is your interface to the system. It presents the following messages, Last successful login for cit1: NEVER last unsuccessful login for cit1: NEVER UNIX System V/386 Release 3.2 cit1 Copyright (C) 1984, 1986, 1987, 1988 AT&T Copyright (C) 1987, 1988 Microsoft Corp. All Rights Reserved Copyright (C) 1988, 1989 The Santa Cruz Operation, Inc /******************************************************/ Welcome to SCO System V/386 Cit1 Central Institute of Technology /******************************************************/ If the line TERM = (unknown) is displayed, you need to enter the terminal type. Parameters can be VT100 VT102 VT200 ANSI The parameter must match that of the telnet configuration file. Enter the appropriate terminal type for your system (vt100). UNIX is ready to interpret and execute your commands. _________________________________________________________________ The objective of the following exercises is to introduce you to basic UNIX commands. The commands and utilities you will use are the same as those on other UNIX systems. At the end of these exercises you will be able to * manipulate files - create, delete, append, concatenate, display, move - count the number of lines, words, characters - extract lines - sort - change permissions on files - paginate, format the output - search for text strings within files * manipulate directories - create, delete - display contents * change your password * use basic commands - display a list of users - display messages and news - time commands - obtain help on command usage - run programs in the background - display the shell environment variables _________________________________________________________________ pwd (print working directory) When a user logs in to a UNIX system, they are located in their own directory space. Users are generally located off the /usr directory. The pwd (print working directory) command displays the pathname of the current directory you are in. This is helpful when you want to know exactly where you are. Type the pwd command, then enter the command response on the line below. pwd ......................................................... _________________________________________________________________ ls (list files) This command is similar to DIR in DOS; it displays a list of all the files in the directory. New users don't have many files in their home directory. Type the command ls You will note that the shell prompt reappears, and there is no file listing of the directory contents. This does not mean that there are no files stored there. Just like DOS, UNIX systems support hidden files. UNIX systems extend the power of commands by using special flags or switches. These switches are one of the most powerful features of UNIX systems. Switches are preceded with a - symbol. Type the command (to illustrate the use of switches) ls -la The switch l stands for long listing, and the a switch is for all files, including directories and hidden files. UNIX responds with the following listing of the directory ls -la total 6 -rw------- 1 ec401 group 526 Apr 15 11:03 .profile Lets explain what all this means. permission settings | number of links to file | | owner of file | | | group | | | | size of file in bytes | | | | | date/time of la st modification | | | | | | filename | | | | | | | -rw------- 1 ec401 group 526 Apr 15 11:03 .profile The first part reveals the permission settings of the files (-rw-r--r--). These have the codes as follows d directory r read w write x execute - no access Note that there are three sets of permission settings. specifies whether a directory entry | permissions for the owner of the file | | permissions for group members | | | permissions for others | | | | - rw- --- --- WHAT are the permission settings for the file .profile in the current directory? owner = ........... group = ........... others= ........... _________________________________________________________________ cat (concatentate) Is a utility used to combine files or typing files to the screen. The cat command sends its output to the console screen (in UNIX we call this standard out or stdout for short). Type the following command to view the file .profile on the screen. cat .profile The format of this command specifies that the cat utility is to use the file .profile as its input, and send the output to the console screen. _________________________________________________________________ Using the cat command to copy data from the keyboard to a file Type the command cat - > temp This specifies that the input is from stdin (- means the keyboard), and writes the output to the file called temp (> means dump into). Type the following lines of text (ignore any typing mistakes, and do not use the cursor arrow keys). Small change got rained on by his own 38 down by the arcade, The marquees weren't weeping, they went stark staring mad, and the cabbies were the old ones who really had it made Press CTRL d to terminate text entry, and the shell prompt returns. What is the command used to view the file temp on the screen. ............................................ The cat utility can also be used to join many files together into a single file. The command, cat temp .profile > temp1 copies the two files (temp and .profile) to a file called temp1. What is the command you would type to copy the file temp to a new file called temp1 using the cat utility. ............................................ The >> is used for appending to an existing file, cat temp >> temp1 _________________________________________________________________ cp (copy) This command stands for copy, and is used for copying one file to another. Type the command cp .profile temp2 This copies the file .profile to another called temp2. If temp2 had already existed, its previous contents would've been erased. Files can also be copied to another directory. The command cp * /usr/tmp would copy all the files in the current directory to the directory /usr/tmp. What is the command you would type to copy the file temp to a new file called temp1 using the cp utility. ............................................ _________________________________________________________________ rm (remove) The rm utility is used for erasing files and directories. Type the command rm temp2 This removes the file. Once a file is removed, it cannot be restored. To cover situations where mistakes might occur, a switch -i appended to this command will request a Yes or No response before deleting the file. Type the command rm -i temp1 NOTE that switches are written before the filenames. Answer Y to the prompt so that temp1 is removed. _________________________________________________________________ head This is used to view the first few lines of a file. It accepts a switch specifying the number of lines to view. The command head -2 temp would list the first 2 lines of the file temp on the console. What is the command to view the first 10 lines of the file .profile. ............................................ _________________________________________________________________ tail This is used to view the last few lines of a file. It accepts a switch specifying the number of lines to view. The command tail -2 temp would list the last 2 lines of the file temp on the console. What is the command to view the last 10 lines of the file .profile. ............................................ _________________________________________________________________ lp (line printer) This command is used to obtain a hardcopy printout of a file. ONLY type this command IF a printer is attached to the computer system. lp temp _________________________________________________________________ wc (word count) This utility displays a count of the number of characters, words and lines in a file. Type the command wc temp This prints out a list of the number of lines, words, and characters respectively. The switches for this utility are -l print line count -c print character count -w print word count What is the command to count the number of words in the file .profile. ............................................ What is the command to count the number of lines in the file .profile. ............................................ _________________________________________________________________ pr (print) The print utility prints the file to stdout. The switches it accepts are -ln set page length in lines to n -wn set line length in characters to n -n number output lines -t do not print page header or trailer -digit number of columns to use +digit start at page number Type the command pr -2 -n temp This prints the file temp to stdout, using two columns per line, numbering each line. _________________________________________________________________ who This command displays a list of the users of the system. Using the -u switch displays a list of those users currently logged into the UNIX server. Type the command, who -u _________________________________________________________________ hello This command sends interactive messages between users. Identify a user from the list printed by the previous who command. When a user receives a message, they should respond. The interactive exchange is cancelled by using the Ctrl D keys. When this occurs, the message end of message appears on the other terminal, and control is returned to the shell. _________________________________________________________________ mesg (message) This command permits or denies messages invoked using write. The switches it uses are -y and -n _________________________________________________________________ news The news command keeps the user informed of current events. _________________________________________________________________ grep The grep command searches a file for a pattern. The following command grep 'change' temp searches the file temp in the current directory for the text string change. Using the * wildcard specifies all files, and using the switch -n will display on which line the text string is found. What is the command to search the file .profile for the text string 'TERM' (case sensitive). ............................................ _________________________________________________________________ time This command times how long it takes to execute a given command. Type the command, time ls -la The command responds with the elapsed time during the command, the time spent in the system, and the time spent in execution of the command. How long does it take to execute the who command? ............................................. _________________________________________________________________ cal (calendar) This command prints a calendar to the screen. _________________________________________________________________ man (manual) This command locates and prints the reference page for a specified item. Type the command, man df The : represents a prompt. Pressing enter will continue the display. To quit from the manual, type q. Briefly explain below in the space provided, a summary of the command function performed by df. ....................................................................... ... ....................................................................... .. ....................................................................... .. The man command can also accept the following names as switches. ADM System Administration C Commands M Miscellaneous F File Formats HW Hardware Dependent S Subroutines and Libraries CP Programming Commands DOS DOS Subroutines and Libraries LOCAL Local utilities for your system An example command which calls up the reference section on 'Miscellaneous features' is (this may not apply to all UNIX systems). man M _________________________________________________________________ Piping commands UNIX systems offer true pipelining. This feature is extremely powerful. It means that the output of one utility can be fed directly into the input of another. The | symbol indicates pipelining in UNIX systems. To illustrate how this works, consider the following command. pr -2 -n temp | wc -l This creates a pipe between the output of the pr utility and the input of the utility wc. The command runs pr, which takes the file temp, adds lines numbers to it and formats it using two columns per line, feeding the output into wc which prints the line count on the stdout. A pipe inter-connects two programs together. _________________________________________________________________ /*----------------------------------------------------------------------------- ---------*/ ANSWER THESE QUESTIONS BEFORE CONTINUING To make a file called temp2 which is a copy of temp1 but with line numbers for each line of the file, the command is ........................................ To get a line numbered printout of file temp1 (which does not have line numbers ), the command is, ........................................ To get a printout of the directory listing, type ........................................ /*----------------------------------------------------------------------------- ---------*/ _________________________________________________________________ passwd (password) All users in UNIX are assigned passwords. Currently, there is a password assigned to the user. This is changed using the passwd utility. The user would type the command passwd The utility asks for the new password (twice, to make sure you didn't misspell it). The user types in the new password, but notice that it will not displayed on the screen when typed (for security reasons). The new password would then be in effect. If the user were to log in again, the system would ask for this password to be typed before allowing access. _________________________________________________________________ mv (move) The mv command is used for moving or renaming files. Type the command mv temp temp2 This renames the file temp to temp2. As an example (do not type this), the command mv temp2 /usr/tmp would move the file temp2 into the directory /usr/tmp (it would no longer appear in your home directory). _________________________________________________________________ DIRECTORY MANAGEMENT UNIX systems support hierarchical directory structures. The commands used for directory maintenance are, pwd print current working directory cd change directory mkdir make a subdirectory rmdir remove a subdirectory _________________________________________________________________ pwd (print working directory) Prints the current working directory on the console screen. In UNIX, the hard disk area is divided into directories, much like abook is sub-divided into chapters and paragraphs. The directories form a hierarcherical level, which simplifies the organisation of the files on the system. The top most directory in UNIX is called root, and consists of a number of subdirectories grouped according to function. bin system binary executables boot file for UNIX boot code dev file names for system devices, terminals, disks etc dos file for code that boots DOS from a DOS partition etc system administration files and tools, system scripts (also tcp/ip information files) lib library routines lost+found unreferenced files are placed here by fsck mnt empty directory used for mounting temporary file system s shlib shared libraries tcb trusted computing base directory, keeps trusted computi ng information, passwords and audit trails tmp scratch pad directory for temporary files. users must have read/write access u user files if a u filesystem is requested during installation unix unix kernel usr application and system specific information As you can see from the previous directory tree, there are lots of sub-directories underneath root. In the space provided below, enter your current directory (use the pwd command). ........................................ When you use the ls command to list the file contents of a directory, those entries which are directories are preceeded with a 'd' character. The sample screen below shows this. ls -la total 19 files drwxr-sr-x 3 b_brown 512 Nov 24 12:05 . drwxr-sr-x 46 root 1024 Nov 23 16:46 .. -rw-r--r-- 1 b_brown 2501 Mar 3 1992 .profil e drwxr-s--- 2 b_brown 512 Nov 24 12:05 datafil es -rw-r----- 1 b_brown 0 Nov 24 12:05 dirlist -rw-r----- 1 b_brown 24 Nov 5 08:59 tmp Note that datafiles is a sub-directory. There are two other subdirectory entries in the listing. . the current directory .. the parent directory (upwards towards /) _________________________________________________________________ cd (change directory) This command is used to change the current directory. For each of the following commands, enter the current working directory after the command is executed. cd . ................................... cd .. ................................... cd / ................................... cd $HOME ................................... _________________________________________________________________ mkdir (make directory) This command makes a sub-directory under the current directory. In the space provided below, enter the command you would use to create a sub-directory called junk. ............................................. _________________________________________________________________ rmdir (remove directory) This command removes (deletes) a sub-directory under the current directory. In the space provided below, enter the command you would use to delete a sub-directory called junk. ............................................. _________________________________________________________________ The SHELL This is probably the most powerful feature of UNIX. It is the user interface to the system, and has a number of built in commands. The shell may also execute a command file (called a shell script). _________________________________________________________________ set Typing the set command will print out a list of all the current shell environments. This is a list of all the variables and settings that the shell currently has. The majority of these are loaded when you first log in. The first thing the shell does is execute the file .profile in the users home directory! Type the command, set Enter in the space provided below, the environment variables printed by the set command. HOME ............................................. LOGNAME ............................................. PATH ............................................. PS1 ............................................. TERM ............................................. _________________________________________________________________ shell variables The shell supports user and system variables. An example of system variables are, PS1 system prompt PS2 secondary line shell prompt HOME home directory LOGNAME login name Variables are assigned values using the = sign. Type the following PS1="Hi there : " This changes the system prompt PS1 from a $ to the text 'Hi there :' Type the command dir="ls -la" This variable dir can now be used as a command. Before executing it, the shell will expand it out. Shell variables, when used as commands, are preceded with a $ symbol. Type the command $dir The shell expands this out to the command 'ls -la' then executes it, resulting in a long listing of the current directory. RESET the shell prompt PS1 back to the $ character. _________________________________________________________________ echo The echo command echoes what follows. Type the command echo "hello world" The shell responds with echo "hello world" hello world Echo can also be used to print out shell variables. Type the following command sequence. sample="Hello world" echo $sample What was printed as a result of the command? ................................... Type set to view the added commands to the shell environment. _________________________________________________________________ Running a secondary shell A secondary copy of the shell is invoked by typing sh Commands are given to a secondary shell to execute, in either the foreground or background mode. The secondary shell will terminate when the command is finished. What does the following command do, assuming the file cmds contains the text string "ls -la"? sh < cmds > dir.dat ............................................. ............................................. ............................................. The secondary shell is terminated by typing exit. _________________________________________________________________ BACKGROUND PROCESSING Another feature of UNIX is running processes in the background. When a command is appended with the & symbol, it is run in the background and the shell prompt immediately returns. This is handy for such things as printing documents, as it allows you to continue doing something else instead of waiting for the document to be finished printing. Each process in UNIX is identified by a PID (process identification number). When a background process is started off, UNIX will print its PID number in square brackets. Type the command ls -l > dirlist& NOTE that the shell prompt immediately returns, and a number in brackets is printed. The & character signals to the shell that the command is to run in the background. 2868 This is the PID number of the background task. You can have more than one background task. Sometimes, you may want to shut down a background task. The kill command is used to shutdown a task, and it accepts the PID number of the task to shutdown. _________________________________________________________________ sleep This command suspends execution for a specified time interval, expressed in seconds. Type the command, sleep 200& This will run the sleep program in the background for 200 seconds. _________________________________________________________________ ps (process status) This command reports on the active processes being run. Type the command, ps You may even see the sleep process listed if it is still running in the background. _________________________________________________________________ [IMAGE] [IMAGE] _________________________________________________________________ Copyright B Brown/CIT, 25 November, 1994, An introduction to SCO UNIX (Rev 2.1)