Systems Supplement for COP 3601
Total Page:16
File Type:pdf, Size:1020Kb
Systems Guide for COP 3601: Introduction to Systems Software Charles N. Winton Department of Computer and Information Sciences University of North Florida 2010 Chapter 1 A Basic Guide for the Unix Operating System 1. 1 Using the Unix On-line Manual Pages Facility The following are some of the Unix commands for which you may display manual pages: cal cat cd chmod cp cut date echo egrep ex fgrep file find gcc gdb grep kill less ln locate ls mail make man mesg mkdir mv nohup nl passwd pr ps pwd rm rmdir set sleep sort stty tail tee time touch tr tty uname umask unset vim wall wc which who whoami write For example, to display the manual pages for the command "cp" enter man cp Note that you may also enter man man to find out more about the "man" command. In addition there may be commands unique to the local environment with manual pages; e.g., man turnin accesses a manual page for a project submission utility named Aturnin@ that has been added to the system. If you enter a command from the Unix prompt that requires an argument, the system will recognize that the command is incomplete and respond with an error message. For example, if the command "cp" had been entered at the Unix prompt the system would respond with the information such as shown below: cp: missing file arguments Try `cp --help' for more information. The "cp" command is a copy command. If the arguments which tell the command which file to copy and where to locate the copied file are missing, then the usage error message is generated. Chapter 1 (Unix Guide) - Page 2 of 44 1. 2 The Unix System Text Editor The Unix text editor supports line oriented editing under the command "ex" and display editing under the command "vi" (here only "vi" is discussed, although it is ‘alias’ed to "vim" on most Linux systems; "vim" employs the same look and feel as "vi", but adds a number of additional features, such as keyword coloring options). The environment variable EXINIT is used to configure the editor each time it is invoked. Normally, users establish the value of EXINIT in the file ".profile" (or .bash_profile or .login), which contains commands executed automatically at log on. For example, a typical ".profile" might contain (among others) the 3 commands EXINIT="set number showmode ignorecase tabstop=2" export EXINIT umask = 066 Command (1) establishes a value for variable "EXINIT" and command (2) "exports" it to the Aenvironment@. Whenever you execute "ex" or "vi" the Aenvironment@ is examined for "EXINIT" and its value is used to configure the editor, in the above case to show the line number of each edit line, display the edit mode status when not in command mode, ignore case distinctions when searching text, and tab in increments of 2. Command (3) establishes the file creation mode mask to provide you with all possible access permissions and deny read and write access to others (the UNIX command "chmod" is used to modify permissions - see below). These commands can also be executed at the UNIX prompt to change the initialization for "ex" or "vi" on the fly. They can also be changed during any editing session (using the :set command, see below). The text file .vimrc is used to configure "vim" whenever it is launched to take advantage of its various features (an example .vimrc file is in the appendix). If .vimrc is present, "EXINIT" is ignored when "vim" is launched. Given that "vi" is usually linked to "vim", launching "vi" most likely will actually launch "vim", so having a .vimrc file is a good idea . The editing features of "vi" are not supported by all terminal types. Starting the editor For line editing the editor is started by entering ex <filename> and for display editing by entering vi <filename> where <filename> (which is an optional entry) is the name of the file you wish to edit (or create, if it does not already exist). When you start under "ex", you can switch to "vi" by entering <line-number> vi where <line-number> is an optional line number at which you want the initial display positioned. Chapter 1 (Unix Guide) - Page 3 of 44 The command Q (capitalized Q) switches your session to "ex" when you are in "vi". 1.3 The vi Editor "vi" has two modes of operation, command mode and input mode. Text is entered from input mode and most editing is done from command mode. Command mode When in "vi" command mode, the "ex" line editing commands can be entered by first entering a ":", then the rest of the command; for example, :set is a line editing command which displays all of the editor configuration values that are active for your editing session. To set a specific option, for example "showmode", enter :set showmode The command :set noshowmode turns the option off. The "showmode" option causes the editor to display mode information in the lower right portion of the screen whenever it is not in command mode. To display the status of all options that can be set enter the command :set all To repeat the last command line (e.g., to repeat a simple search and replace), enter @: File positioning commands (Command Mode) Most of the file positioning commands can be preceded by an optional <count> value, which specifies how may times to do the operation (default is once). The following is only a partial listing of the available commands: <Ctrl> f Forward full screen <Ctrl> b Backward full screen <Ctrl> d Scroll down half screen <Ctrl> u Scroll up half screen <Ctrl> e Scroll down one line <Ctrl> y Scroll up one line + Move cursor to 1st non-blank on next line - Move cursor to 1st non-blank on previous line $ Move cursor to end of current line H Home window line L Last window line M Middle window line B,b Back a word E,e Forward a word Chapter 1 (Unix Guide) - Page 4 of 44 <number> G Line number to go to (omit line number to go to end of file) /<re> Forward to next text matching regular expression ?<re> Back to prior text matching regular expression n Repeat most recent search, going forward Repeat most recent search, going back N Delete commands (Command Mode) dd Deletes a line (<cnt>dd deletes <cnt> lines) dw Deletes from cursor to end of word including trailing space de Same as dw, but leaves trailing space d$ Deletes rest of line x Deletes one letter Put command (Command Mode) Inserts the most recent deletion after cursor or on next line ( case) p dd Leaving the editor (Command Mode) vi :q Quit "vi" when file is unchanged ("ex" command) :q! Quit "vi", save no changes ("ex" command) :wq (see file I/O in section 1. 4 for more information on the "w" command) or Write and quit, saving changes ZZ Other useful commands (Command Mode) <Ctrl> L This command causes the screen to refresh itself from what is in the working buffer. u Undoes changes made by the previous editing command U Undoes changes to current cursor line only J Joins the current line and the next Q To switch to the line editor "ex" . To repeat the last (non-ex) command Locates the matching bracket (or parenthesis, or brace) % Input mode While in the command mode, entering any one of the following commands will cause an entry into the input mode. a Append after the cursor i Insert before cursor A Append at end of line (same as "$a") o Open line below O Open line above r Allows replacement of a single letter cw, ce, c$ Does dw or de or d$ and then goes into input mode R Allows replacement from cursor forward, unchanged text remains Chapter 1 (Unix Guide) - Page 5 of 44 Returning to command mode Most commands are entered from command mode. The ESC key returns you to the command mode. 1. 4 The Editor ex While editing is normally done under the display mode provided by "vi", there are a number of useful block operation and other commands accessible only via the line editor "ex". The "set" command noted above is one of these. Keep in mind that any of these can be entered from "vi" by preceding them with " ". When actually in " ", the colon is automatically supplied. : ex A range of lines is specified by a pair of line numbers, for example 23,34 specifies lines 23 through 34. File I/O <line-no> r <file-name> Read the named file into the edit buffer after the specified line (line 0 = at the beginning) <range> w <file-name> Write the specified range of lines to the named file, the whole buffer, if no range is given Other block operations (the current line only, if no range is given) <range> d Delete specified range of lines <range> co <dest-line> Copy specified range of lines, placing after the destination line <range> m <dest-line> Move specified range of lines, placing after the destination line <range> > Move the specified lines the value of Ashiftwidth@ to the right (installs spaces, not tabs) <range> < Move the specified lines the value of Ashiftwidth@ to the left (installs spaces, not tabs) Search and replace <range> s/<pattern>/<replacement>/gc (see note below RE separator character “/”) options: g = all occurrences = confirm before replace c Over the specified range, the first occurrence of the pattern in each line is replaced if no options are specified. Note: a control character may be entered in a <pattern> or <replacement> string by first entering a preceding <Ctrl V>.