The command more is used to display the contents of a file on the screen. The command is particularly useful for viewing long files since the display stops at the bottom of the screen. The following is a listing of a program in the Icon programming language:
% more lookup.icn # program to look up words (given at the terminal) in the # computer usable version of the OALD # last change 18.12.91 # set global parameters global k # main body procedure main() # input word to be searched for write("Give me a word: \n") word:=read() # this the important line - call the 'lookup' procedure if not write(lookup(word)) then write("Not found in the dictionary.") end procedure lookup(voc) # connect to the dictionary (dict:=open("/home/sunserv1_a/ecl6rsh/oald.mitton/cuv2")) | stop("can't open the dictionary") # lookup algorithm every k:=1 to *voc do { --More-- (75%)
The message at the bottom of the screen means that 75% of the file has been viewed so far. (The amount shown on screen will depend on the type of terminal you are using.) You can now do the following:
To continue viewing press the space bar
To view the next line press <RETURN>
To quit press the <q> key
To jump to the next occurrence of a string of characters type /string
For a list of valid commands press the <h> key.
The pg command is also available on some systems. This is an alternative to more
% pg lookup.icn # program to look up words (given at the terminal) in the # computer usable version of the OALD # last change 18.12.91 # set global parameters global k # main body procedure main() # input word to be searched for write("Give me a word: \n") word:=read() # this the important line - call the 'lookup' procedure if not write(lookup(word)) then write("Not found in the dictionary.") end procedure lookup(voc) # connect to the dictionary (dict:=open("/home/sunserv1_a/ecl6rsh/oald.mitton/cuv2")) | stop("can't open the dictionary") # lookup algorithm every k:=1 to *voc do { bit:=bite(voc)
Commands can be typed to the ':' prompt at the bottom of the screen: Type <RETURN> to view the next screen. Type <h> for a list of valid commands.
PRACTICE
If you have a file longer than 20 lines use pg to view it. Compare the use of pg with more. Use them both on the file /etc/passwd, and find the listing for your own username.
The command grep is used to search a file for a string of characters. For example, to search the file lookup.icn for the character '#' (which designates comments in the program), use the command:
% grep # lookup.icn # program to look up words (given at the terminal) in the # computer usable version of the OALD # last change 18.12.91 # set global parameters # main body # input word to be searched for # this the important line - call the 'lookup' procedure # connect to the dictionary # lookup algorithm
A lot of pattern matching operations can be carried out with grep. The following example shows the use of a regular expression. In this example, the search is restricted to lines beginning with the 'p' character.
% grep " p" lookup.icn procedure main() -output starts here procedure lookup(voc) procedure bite(voc2)
You will learn more about pattern matching expressions later.
The actual key sequences for the following operations can vary from between different systems and different terminals. The most commonly used key sequences are described below. If it is different on your system, remember the correct sequence and use it whenever the key sequences below are referred to later in the text. Where possible the operation itself is named (e.g. end-of-file), and not just the key sequence.
If you make a typing mistake you can delete the last character typed by using your delete key, which is usually the one marked <DEL> or <DELETE>.
If you make many typing mistakes you can delete the entire line by typing ^U.
NOTE Remember ^U means "press <CTRL> and <u> keys simultaneously".
If you wish to terminate the execution of a command type ^C.
In many Unix commands you need to finish your input with an end-of-file character. The default end-of-file character is ^D.
This is usually called 'obtaining hard copy output', as distinct from output to the screen or a file. The command lpr sends a file to the line printer:
% lpr file1
Note that the command lp is used on some Unix systems. The command:
% lpr -Pprinter file
is used to submit the file to a specific printer.
The locally developed command printers can be used to obtain a list of printers.
The command man is used to display help on the syntax of Unix commands.
The format of this command is:
% man [option] [file]
For example to obtain help information on the who command, type:
% man who
The keyword option -k keyword is used to display a list of help files associated with the keyword. For example to display a list of all man files associated with password type the command:
% man -k password getpass(3) read a password passwd(1) change login password passwd(5) password file
The command man automatically invokes the more program for viewing files. You can use the normal more commands to continue viewing.
If you have any problems that can't be solved by referring to the manual, please consult your supervisor or the Advisory Service. The Help Desk can be contacted in person in the User Access Area, on the telephone on extension 5366, or by email to helpdesk. Also the LUCS Unix system operators can be contacted on telephone extension 5380. With non-urgent problems, an email message to your supervisor is usually the most efficient way of getting help. (See next chapter on how to use email.)
1. Display a list of logged on users.
2. Obtain further information for a particular user using the finger command.
3. Use the man command to obtain further information on the finger command.
4. Use the man -k command to find what manual entries there are related to passwords.
5. Use the grep command to search the file example1 for occurrences of the string 'water'.
6. Use man and the keyword option to find out more information on communications and e-mail in Unix.
7. Print out a file on paper.