UNIX Shell Script – Shell Commands Placed in a File for Later Execution

UNIX Shell Script – Shell Commands Placed in a File for Later Execution

UNIX Shell script – shell commands placed in a file for later execution Files Devices Text Files Program Files Binary Files I/O device independent input indirection < output indirection > cat Interprocess Communication pipe -- used to transmit data from one file to another filter – used to select data items from the output of one pipe‟s data flow for retransmission through another pipe Erase Keys Aborting Program Execution Key Backspace Delete Ctrl-H Ctrl-C # Printing Line Deletion Keys lp <dest> check Ctrl-U lpr <dest> check @ Password Word Deletion Key passwd Ctrl-W Logging Out New Command Line Ctrl-D Ctrl-R redraws command line with exit current logout command (eliminates garbage on old line) Vi Editor vi <file name> o if no file name is provided upon entry, vi will request a name at the termination of the editor o upon opening a file, vi is in Command Mode o Escape “beep” Command Mode Insert Mode :set showmode mode display on o i insert text before cursor : set nu line numbers on o I insert text at beginning of current line :set nonu line numbers off o a append text after cursor o A append text to end of current line o open and put text in a new line below current line o open and put text in a new line above current line Insert Mode Command Mode o Escape Command Mode Line Mode o : Command Mode Editing o r replace single character under cursor o R replace multiple characters, starting at the current cursor position, <Esc> to exit o cw change the current word with new text, starting with the character under the cursor, <Esc> to exit o cNw change N words beginning with character under cursor, <Esc> to exit e.g., c5w changes 5 words o C change (replace) the characters in the current line, <Esc> to exit o cc change (replace) the entire current line, <Esc> to exit o Ncc or cNc change (replace) the next N lines, starting with the current line, <Esc> to exit e.g., 5cc &/or c5c changes the next 5 lines including the current line o x delete the single character under the cursor o Nx delete N characters, starting with character under cursor, e.g., 5x deletes 5 characters o dw delete the single word beginning with character under cursor o dNw delete N words beginning with character under cursor; e.g., d5w deletes 5 words o D delete the remainder of the line, starting with current cursor position o dd delete entire current line o Ndd or dNd delete N lines, beginning with the current line; e.g., 5dd deletes 5 lines o yy copy (yank, cut) the current line into the buffer o Nyy or yNy copy (yank, cut) the next N lines, including the current line, into the buffer o p put (paste) the line(s) in the buffer into the text after the current line o P put (paste) the line(s) in the buffer into the text before the current line o u undo last action (toggle switch) o U undo all changes made to the current line o . repeat last text change at current position File Recovery vi –r <file name> retrieve crashed file Saving Files o :w<Return> write current contents to file named in original vi call o :w newfile<Return> write current contents to a new file named newfile o :w! oldfile<Return> write current contents over a pre-existing file, oldfile Exiting Vi o :x<Return> quit vi, writing out modified file to file named in original invocation o :wq<Return> quit vi, writing out modified file to file named in original invocation o :q<Return> quit (or exit) vi prompting for file name o :q!<Return> quit vi even though latest changes have not been saved for this vi call Command Mode Cursor Moving o j or <Return> or [down-arrow] move the cursor down one line o k or [up-arrow] move cursor up one line o h or <Backspace> or [left-arrow] move the cursor left one character o l or <Space> or [right-arrow] move the cursor right one character o 0, i.e., zero, move the cursor to start of current line o $ move the cursor to end of current line o w move the cursor to beginning of next word o b move the cursor back to beginning of preceding word o :0<Return> or 1G move the cursor to the first line in the file o :n<Return> or nG move cursor to line n, e.g., 5<Return> or 5G moves the curser to line 5 o :$<Return> or G move cursor to last line in file o ctrl-f scrolls down one screen o ctrl-b scrolls up one screen o ctrl-u scrolls up a half a screen o ctrl-d scrolls down a half a screen Command Mode Screen Manipulation o Ctrl-f move forward one screen o Ctrl-b move backward one screen o Ctrl-d move down (forward) one half screen o Ctrl-u move up (back) one half screen o Ctrl-l redraws the screen o Ctrl-r redraws the screen, removing deleted lines Line Numbers o :.= returns line number of current line at bottom of screen o := returns the total number of lines at bottom of screen o Ctrl-g provides the current line number, along with the total number of lines, in the file at the bottom of the screen o :set number sets line numbers o :set nonumber eliminates line numbers Unix Commands cat entire screen delivered to target, e.g., screen more <sp> next page no EOF display; direct return to shell pg <return> next page EOF display K shell who or w displays list of users currently on the system talk or write mailx check – may be obsolete finger displays list of all users of the system mesg returns your current message status mesg n blocks messages to your terminal mesg y allows messages to pop up on your screen at will man displays manual WARNING – may not be useful man –k displays list of keywords date head <file name> displays first ten lines of file head –n <file name> displays first n lines of file sed –n <file name> displays first n lines of file grep „search-string‟ <file-name> searches <file-name> for occurrences of any string containing „search-string‟ as a subsring tail <file name> displays last ten lines of file tail –n <file name> displays last n lines of file sort <file-name> sorts the contents of <file-name> line-by-line uniq <file-name> displays <file-name> skipping adjacent duplicate lines sort <file-name> | uniq > newfile produces a file named newfile that contains no duplicate lines whereis <tool name> not SVR4 path to <tool name>, location in man provides listing of multiple occurrences of <tool name> which <tool name> not SVR4 returns <tool name> in the current path Special Characters (Shell Usage Only) & ; | * ? „ “ ` [ ] ( ) $ < > { } ^ # / | % ! ~ Quoting Special Characters \”Hello\” treated as “Hello” \cntrl-h treated as cntrl-h \cntrl-u treated as cntrl-u “**” Coffee treated as ** Coffee File Structure Directories Root directory / Home directory . Relative pathnames working directory Parent directory .. Absolute pathnames root directory Working directory pwd path to working directory rm cd return to your home directory rmdir ls mkdir ls -l mv <file> <dir> ls –a mv <file1> <file2> cp source-file destination-file Standard Directories / root – ancestor of all files in he filesystem /home one of several subdirectories of root that may contain users home directories /usr contains subdirectories that contain system information /usr/bin contains the standard Unix programs /bin same as usr/bin /usr/sbin system administration utilities /usr/ucb contains BSD utilities /usr/bsd contains BSD utilities /sbin system administration utilities /etc configuration & other system files /etc/passwd classical directory for password files <not currently used> /var subdirectories contain files whose contents vary as system runs temporary files, system logs, spooled files, etc. /dev contains peripheral device files /tmp contains temporary files Access Permissions file-types o - file o d directory o l hard link -rwx r- - r- - 1 cputnam c322 6753 May 5 12:06 syllabus o s symbolic link drwx - - - - - - cputnam 413 May 5 12:15 grades permissions owner group universe r w x r w x r w x link-count owner-name group-name univ-name file-size creation/modification date & time file-name chmod 777 syllabus changes permissions to rwx for group and universe, i.e., 111 111 111 binary 7 7 7 hexadecimal chmod 744 syllabus changes permissions to r - - for group and universe, i.e., 111 100 100 binary 7 4 4 hexadecimal Links home alex jenny File a1 File a2 File j1 working directory alex alex is creating a link to jenny ln a2 /home/jenny/a2 creates link remove link by removing the file Shells Entering Command Line Get Next Character yes cntrl-h ForgeForgett Previous Character in Buffer no yes cntrl-u Forget Entire Buffer no no Store Character return in Buffer yes Pass buffer to shell for processing Processing the Command line Get FirstFirst Word; Save as CommandCommand Name no Get Next Word; NEWLINE Save as Argument yes Execute Program Program Exists? no yes IssueIssue PromptPrompt Terminal File device file -- /dev directory terminal file name – who listing – name following login name who am i cputnam ttyp19 May 5 19:31:16 writing to terminal displays on monitor reading from terminal reads input from keyboard login shell directs standard output to the device file monitor standard input to the device file keyboard cat file1 – executed with the argument file1 writes file1 to the standard output cat – executed without arguments reads from the standard input writes to the standard output until cntrl-d is entered EOF signal sent to cat redirection standard input cat file1 < file0 standard output cat file1 > file2 cat file1 file2 file3 > file4 copies the contents of files 1, 2 & 3 to file4; the original contents of file4 are destroyed appending cat file1 >> file0 appends contents of file1 to the tail of file0 pipes connect stdout of first command to srdin of second command can be used on any command that accepts input from the command line or from stdin o cat file1 | tr .

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    8 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us