Week 8: Linux / ubuntu Dr. I. H. Shah. / CSCS 301 Fall 2009
Linux – The Shell A shell is an interpreter that provides an interface between users and the O.S. It executes all the commands we enter and hence lets us run programs. Several shells developed in Linux are: –Bourne Again Shell (BASH); this is default shell., –Public Domain Korne shell. –TCSH shell. –Z-shell. The Command Line –It is a single line containing command and its options and arguments. –A command is typed after shell prompt which is usually $ in BASH. –Syntax of a command: command options arguments // comments –An option is a single letter code preceded by a hyphen (-) which modifies the behavior of the command. –Many file management commands take file name (s) as argument (s).
Running Commands / Utilities Command Description pwd Print the path name of the working directory. date Print date and time. ls List (display) the contents of the working directory. ls –l ls –l d1 List detailed contents of the working directory List detailed contents of the directory d1 mkdir d1 Create a directory named d1 rmdir d1 Delete a directory named d1 ( d1 should be empty) cp file1 file2 Copy file1 into file2; if file2 exists, it is overwritten otherwise it is created. rm file1 Delete file1 clear Clears the screen. man command_name Give details of the command To run a utility, type a command and press enter. The following are a few basic commands. Try them.
Creating a file : The vi editor To invoke vi editor type the command: $ vi file_name // the file_name is optional and $ is already there as prompt. A blank screen like the one shown below appears. ~~~~~~~~~~~~~~~~~~
The vi editor The vi editor has two modes: Command mode and the Text Entry mode; the text entry mode being the default mode. Text Entry mode To go from the command mode to the text entry mode use any of the keys given in the following table; each key takes you into text entry mode in a slightly different manner, mentioned against it. keyAction iText is inserted before the cursor. aText is inserted after the cursor. IText is inserted at the beginning of the current line. AText is inserted at the end of the current line. oA new line is created below the current line and text is inserted. OA new line is created above the current line and text is inserted. RText is replaced.
The vi editor (contd.) Command mode: Text can be edited. To go from the text entry mode to the command mode press esc key. the common vi editing features are: oMoving the cursor oDeleing text oReplacing text oPasting text oSearching through text oSaving or loading files oMiscellaneous ( quitting vi, etc.)
The vi editor : Moving the Cursor keyAction jDown one line. kUp one line. lOne character left. hOne character right. ^The start of the current line. $The end of the current line. wForward one word bBack one word HTop of the screen. nn To line nn. Ex. Explore more cursor movement keys.
The vi editor : Saving / Quitting a file Press esc key to go to the command mode, Type : (this will move the cursor to the bottom of the screen) Use the following key combination: keyAction wSave the file (write the file to the disk); if no name has already been given to the file, a file name is required. wqSave the file and quit the editor. q!Quit the editor without saving any changes. qQuit the editor (if no changes have been made to the file.