Transcript of "Unix(introduction)"

4.
04/23/11 UNIT-I : UNIX Introduction <ul><ul><li>History of UNIX </li></ul></ul><ul><ul><li>In 1965 , Bell laboratories joined with MIT and General Electric to develop a new operating system called Multics (Multiplexed Information Computing Service) , which would provide multi-user , multi-processor and multi-level (hierarchical) file system. </li></ul></ul><ul><ul><li>In 1969 , AT&T developed the first UNIX file system with a few utilities and gave the name UNIX to it. In 1970 , January 1 time zero for UNIX started. In 1973 , UNIX was re-written in C by Dennis Ritchie . Being written in a high level language decreased the effort to port it to new machines. </li></ul></ul><ul><ul><li>In 1980 , BSD 4.1 (Berkelely Software Development ) was developed. </li></ul></ul><ul><ul><li>In 1983, SunOs , BSD 4.2 , System were released. </li></ul></ul><ul><ul><li>In 1983 , AT&T and Sun Microsystems jointly developed System V Release 4 (SVR 4). </li></ul></ul><ul><ul><li>This was later developed in UNIX ware and Solaris 2. </li></ul></ul>

13.
<ul><li>Boot Block :- This block contain a small boot program and partition table. </li></ul><ul><li>Super Block:- It contains globle information about the file system.It also maintains a free list of inodes and data blacks that can be immediately allocated by the kernel when creating a file. </li></ul><ul><li>This is mainly what it contains:- </li></ul><ul><ul><li>The size of the file system. </li></ul></ul><ul><ul><li>The block size used by the file system. </li></ul></ul><ul><ul><li>The number of free data blocks available and a partial list of immediately allocable free data blocks. </li></ul></ul><ul><ul><li>Number of free inodes available and a partial list of immediately usable inodes. </li></ul></ul><ul><ul><li>Last time of updating. </li></ul></ul><ul><ul><li>The state of the file system (Whether “clean “ or “dirty”). </li></ul></ul><ul><li>Inode Block :- This region contains the inode for every file of the file system. </li></ul><ul><li>Data Block:- All data and programs created by users reside in this area. </li></ul>04/23/11 UNIT-I : UNIX Introduction

15.
<ul><li>Unix is a operating system, used by most large, powerful computers. </li></ul><ul><li>A commands is an instruction given th the shell ; kernel will obey that instruction. UNIX provides several commands for its users to easily work with it. </li></ul><ul><li> The general format of a command is :- </li></ul><ul><li>command -options command_arguments </li></ul>04/23/11 UNIT-I : UNIX Introduction

17.
<ul><li>1.ls(list)-To shows the list of files and direrctories. </li></ul><ul><li>Syntax: ls [-option] [name of file name/ directory name] </li></ul><ul><li>Where </li></ul><ul><li>Option Description </li></ul><ul><li>-x Multicolumnar Output </li></ul><ul><li>-F Marks executables with *,directories with /, and symbolic links with @ </li></ul><ul><li>-a Shows all filenames beginning with a dot including . And .. </li></ul><ul><li>-R Recursive list (Directory., Subdirectory., files) </li></ul><ul><li>-r Sorts filename in reverse order </li></ul><ul><li>-1 One filename in each line </li></ul><ul><li>-l long listing (Seven attributes of a file) </li></ul><ul><li>-d dirname Lists only dirname if dirname is a directory </li></ul><ul><li>-t Sorts filenames by last modification time </li></ul><ul><li>-lt Sorts listing by last modification time </li></ul><ul><li>-u Sorts filename by last access time </li></ul><ul><li>-lu Sorts by ASCII collating sequence but listing shows last access time </li></ul><ul><li>-lut As above but sorted by last access time </li></ul><ul><li>-i Displays inode number </li></ul>04/23/11 UNIT-I : UNIX Introduction

19.
<ul><li>‘ *’ Represents any number of characters. </li></ul><ul><li>‘ ?’Represents a single character. </li></ul><ul><li>‘ [RANGE]’Represents character list. </li></ul><ul><li>‘ [Character_List]’ Matches any single character, Which is specified in Character List. </li></ul><ul><li>‘ [!Character_list]’ Matches any single character , Which is not specified in Character List. </li></ul><ul><li>Example:- </li></ul><ul><li>$ls pgm* </li></ul><ul><li>This command will list out all the filenames of the current directory, which are starting with “pgm”.the sufffix to pgm may be any number of characters. </li></ul><ul><li>$ls *s </li></ul><ul><li>This command will display all the filenames of the current directory , which are ending with “s”. </li></ul><ul><li>$ls ?gms </li></ul><ul><li>This command will display four character filenames, which are ending with “gms” starting with any of the allowed character. </li></ul><ul><li>$ls gms? </li></ul><ul><li>This command will display four character filenames, which are starting with “gms” ending with any of the single character. </li></ul>04/23/11 UNIT-I : UNIX Introduction

20.
<ul><li>“ []” Represents a subset of related filenames. This can be used with range operator “-” to access a set of files . Multiple ranges must be separated by commas. </li></ul><ul><li>$ls pgm[1-5] </li></ul><ul><li>This command will list only the files named , pgm1 , pgm2 , pgm3 , pgm4 , pgm5 if they exist in the current directory. </li></ul><ul><li>$ls pgm[1-5],[11-15] </li></ul><ul><li>This command will list only the files named , pgm1 , pgm2 , pgm3 , pgm4 , pgm5, pgm11 , pgm12 , pgm13 , pgm14 , pgm15 if they exist in the current directory. </li></ul><ul><li>$ls a[bc]d </li></ul><ul><li>This command will list only the files named abd and acd </li></ul><ul><li>$ls a[!bc]d </li></ul><ul><li>This commands will list only the files named agd , ahd , akd , amd except abd and acd. </li></ul>04/23/11 UNIT-I : UNIX Introduction

21.
<ul><li>2.mkdir[Make Directory] </li></ul><ul><li>This command is used to create new directory. </li></ul><ul><li>General format is :- </li></ul><ul><li>mkdir [-p] <directory-name1> <directory-name2> </li></ul><ul><li>The option –p is used to create consequences of directories using a single mkdir command. </li></ul><ul><li>Example:- </li></ul><ul><li>$mkdir ibr </li></ul><ul><li>This command will create ‘ibr’ a subdirectory of the current directory. </li></ul><ul><li>$mkdir x x/y </li></ul><ul><li>This command will create x as a subdirectory of current working directory , y as subdirectory of x. </li></ul><ul><li>$mkdir ibr/ib/i </li></ul><ul><li>This command will make a directory i as a subdirectory of ibr/ib, but the directory structure –ibr/ib must exist. </li></ul><ul><li>$mkdir –p ibr/ib/i </li></ul><ul><li>Then for the current directory , a subdirectory named ibr is created . Then for the directory ibr , a subdirectory named ib is created . After that the subdirectory i as created as a subdirectory of the directory ib. </li></ul>04/23/11 UNIT-I : UNIX Introduction

22.
<ul><li>3.rmdir[Remove Directory] </li></ul><ul><li>This command is used to remove (delete) the specified directory. A directory should be empty before removing it. </li></ul><ul><li>Syntax:- rmdir [-p] <directory_name1> <directory_name2> </li></ul><ul><li>The option –p is used to remove consequence of directories using a single rmdir command. </li></ul><ul><li>Example:- </li></ul><ul><li>$rmdir ibr </li></ul><ul><li>This command will remove the directory ibr , which is the subdirectory of the current directory. </li></ul><ul><li>$rmdir ibr/ib/i </li></ul><ul><li>This command will remove the directory i only. </li></ul><ul><li>$rmdir –p ibr/ib/i </li></ul><ul><li>This commad will remove the directory i , ib and ibr consequently. </li></ul>04/23/11 UNIT-I : UNIX Introduction

23.
<ul><li>4.cd[Change Directory] </li></ul><ul><li>This command is used to change working directory to a specified directory. </li></ul><ul><li>Syntax:- </li></ul><ul><li>cd <existing_directory_name> </li></ul><ul><li>Example:- cd /home/ibr </li></ul><ul><li>Then the directory /home/ibr becomes as the current working directory. </li></ul><ul><li>5.pwd[Present Working Directory / Print Working Directory] </li></ul><ul><li>This command displays the full pathname for the current working directory. </li></ul><ul><li>Example :- </li></ul><ul><li>$pwd </li></ul><ul><li>Output:- /home/bmi </li></ul><ul><li>Your present working directory is /home/bmi. </li></ul>04/23/11 UNIT-I : UNIX Introduction

24.
<ul><li>5. Find </li></ul><ul><li>find is one of the power tools of the UNIX system. It recursively examines a directory tree to look for files matching some criteria and then takes some action on the selected files. </li></ul><ul><li>Syntax:- </li></ul><ul><li>find <path_list> <selection _criteria> action </li></ul><ul><li>This is how find operators: </li></ul><ul><li>First , it recursively examines all files in the directories specified in path_list. </li></ul><ul><li>It matches each file for one or more selection_criteria. </li></ul><ul><li>Finally , it takes some action on those selected files. </li></ul><ul><li>Example:- </li></ul><ul><li>$find / -name a.out –print </li></ul><ul><li>Output:- /home/kumar/scripts/a.out </li></ul><ul><li>/home/tiwari/scripts/reports/a.out </li></ul><ul><li>/home/sharma/a.out </li></ul>04/23/11 UNIT-I : UNIX Introduction

25.
<ul><li><Selection_Criteria> </li></ul>04/23/11 UNIT-I : UNIX Introduction -name <filename> Selects the file specified in <filename> If wild cards are used then double quote <filename> -user <username> Selects files owned by <username> -type d Selects directories. -size +n -n Selects files that are regular than /less than “n” blocks (1 blocks= 512 bytes) -mtime n +n -n Selects files that have been modified on exactly n days / more than n days / less than n days. -mmin n +n -n Selects files that have been modified on exaclty n minutes / more than n minutes / less than n minutes. -atime n +n -n Seelcts files that have been accessed on exactly n days / more than n days /less than n days -amin n +n -n Selects files that have been accessed exactly n minutes / more than n minutes /less than n minutes.

29.
<ul><li>1.cat :- Means Concatenate i.e. To add more than one string. </li></ul><ul><li>It is one of the most important command of UNIX Operating System. It is useful for creating a file and displaying a contents of file in a small terminal . </li></ul><ul><li>cat command provides the various facility in UNIX Operating System. This various facility is also called various flavors of cat command. </li></ul>04/23/11 UNIT-I : UNIX Introduction

38.
<ul><li>3. rm [Remove]:- </li></ul><ul><li>This am command is used to remove a file from the specified directory. To remove a file , you must have write permission for the directory that contains the file , but you need not have permission on the file itself . If you do not have write permission on the file , the system will prompt before removing. </li></ul><ul><li>Syntax:- </li></ul><ul><li>rm [-option] <filename> </li></ul><ul><li>where options are as follows:- </li></ul><ul><li>r - deletes all directories including the lower order directories. Recursively deletes entire contents </li></ul><ul><li> of the specified directory and the directory itself . </li></ul><ul><li>i - Prompts before deleting </li></ul><ul><li>f - Removes write – protected files also, without prompting. </li></ul><ul><li>Example:- </li></ul><ul><li>$rm myfile1 </li></ul><ul><li>This command deletes the file myfile form the current directory. </li></ul><ul><li>$rm –f /usr/ibrahim </li></ul><ul><li>This command deletes all the files and subdirectories of the specified directory /usr/ibrahim. </li></ul><ul><li>Note that the directory ‘ibrahim’ also will be delted. </li></ul>04/23/11 UNIT-I : UNIX Introduction

41.
<ul><li>6.ln(Link) </li></ul><ul><li>This command is used to establish on additional filename to a specified file.It doesn’t mean that creating more copies of the specified file. </li></ul><ul><li>Syntax:- </li></ul><ul><li>ln <filename> <additional_filename> </li></ul><ul><li>Where <Filename> is the file name for which <additional_filename> is to located on any directory. Thus UNIX allows a file to have more than one name and yet maintain a single copy in the disk. But changes to one of these files are also reflected in the disk .But changes to one of these files are also reflected to the others. If you delete one filename using rm command , then the other link names will still exist. </li></ul><ul><li>Example:- </li></ul><ul><li>$ls –l test1.txt </li></ul><ul><li>-rw-rw-r-- 1 bmi bmi 75 jan 13 14:35 test1.txt </li></ul><ul><li>$ln test1.txt test2.txt </li></ul><ul><li>$ls –l test*.txt </li></ul><ul><li>-rw-rw-r-- 2 bmi bmi 75 jan 13 14:35 test1.txt </li></ul><ul><li>-rw-rw-r-- 2 bmi bmi 75 jan 13 14:35 test2.txt </li></ul><ul><li>$rm test1.txt </li></ul><ul><li>$ls –l test2.txt </li></ul><ul><li>-rw-rw-r-- 1 bmi bmi 75 jan 13 14:35 test2.txt </li></ul>04/23/11 UNIT-I : UNIX Introduction

47.
<ul><li>12. tail </li></ul><ul><li>This command displays the end of the specified file. </li></ul><ul><li>Syntax:- </li></ul><ul><li>tail -n <filename> </li></ul><ul><li>Example:- </li></ul><ul><li>$cat student.txt </li></ul><ul><li>Mohan always keeps himself to himself. </li></ul><ul><li>We were in a hurry. The road being zigzag , </li></ul><ul><li>We had to cut off a corner to reach in time. </li></ul><ul><li>In his youth , he was practically rolling in money. </li></ul><ul><li>$tail -1 file1.txt </li></ul><ul><li>Output:- </li></ul><ul><li> In his youth , he was practically rolling in money. </li></ul><ul><li>$tail -2 file1.txt </li></ul><ul><li>Output:- </li></ul><ul><li>We had to cut off a corner to reach in time. </li></ul><ul><li>In his youth , he was practically rolling in money. </li></ul>04/23/11 UNIT-I : UNIX Introduction

48.
<ul><li>12. head </li></ul><ul><li>This command displays the top of the specified file. </li></ul><ul><li>Syntax:- </li></ul><ul><li>head -n <filename> </li></ul><ul><li>Example:- </li></ul><ul><li>$cat student.txt </li></ul><ul><li>Mohan always keeps himself to himself. </li></ul><ul><li>We were in a hurry. The road being zigzag , </li></ul><ul><li>We had to cut off a corner to reach in time. </li></ul><ul><li>In his youth , he was practically rolling in money. </li></ul><ul><li>$head -1 file1.txt </li></ul><ul><li>Output:- </li></ul><ul><li> Mohan always keeps himself to himself. </li></ul><ul><li> $tail -2 file1.txt </li></ul><ul><li>Output:- </li></ul><ul><li>Mohan always keeps himself to himself. </li></ul><ul><li>We were in a hurry. The road being zigzag , </li></ul>04/23/11 UNIT-I : UNIX Introduction

54.
<ul><li>2. Who </li></ul><ul><li>Since UNIX is a multi-user operating system , several users may work on this system. This command is used to display the users who are logged on the system currently. </li></ul><ul><li>Syntax & Example :- </li></ul><ul><li>$who </li></ul><ul><li>Output:- </li></ul><ul><li>Aman tty1 jan 07 10:17 </li></ul><ul><li>Shwetabh tty2 jan 07 10:20 </li></ul><ul><li>Neha tty4 jan 07 10:30 </li></ul><ul><li>The first column of the output represents the user names. The second column represents the corresponding terminal names and the remaining columns represents the time at which the users are logged on. </li></ul>04/23/11 UNIT-I : UNIX Introduction

56.
<ul><li>4.man (Manual) </li></ul><ul><li>This command displays the syntax and detailed usage of the UNIX command , which is supplied as argument. </li></ul><ul><li>Syntax :- </li></ul><ul><li>$man <UNIX_COMMAND> </li></ul><ul><li>Example:- </li></ul><ul><li>$man wc </li></ul><ul><li>This will display the help details for “wc” command. </li></ul><ul><li>Almost all of the command offer – help option that displays a short listing of all the options. </li></ul><ul><li>$wc --help </li></ul>04/23/11 UNIT-I : UNIX Introduction

57.
<ul><li>5. cal (calculator) </li></ul><ul><li>This command will display the calender for the specified month and year. </li></ul><ul><li>Syntax :- </li></ul><ul><li>$cal [month] <year] </li></ul><ul><li>where month can be ranged form 1 to 12 </li></ul><ul><li>Example:- </li></ul><ul><li>$cal 2008 </li></ul><ul><li>This command will display calender for thr year 2008 (from 1 to 12 months). </li></ul><ul><li>$cal 1 2008 </li></ul><ul><li>This command will display the calender for the month january of the year 2008. </li></ul>04/23/11 UNIT-I : UNIX Introduction

60.
<ul><li>8. bc [Basic Calculator] </li></ul><ul><li>This command is used to perform arithmetic operation on integer as well as on floats (Decimal Number]. </li></ul><ul><li>Type the arithmetic expression in a line and press [ENTER] key. Then the answer will be displayed on the next line. After you have finished your work press [ctrl+d] keys to endup. </li></ul><ul><li>Example :- Add 10 and 20 </li></ul><ul><li>$bc </li></ul><ul><li>10 + 20 </li></ul><ul><li>30 </li></ul><ul><li>^d </li></ul>04/23/11 UNIT-I : UNIX Introduction

64.
<ul><li>PIPE :- </li></ul><ul><li>Pipe is a mechanism in which the output of one command can be redirected as input to another command. </li></ul><ul><li>Syntax:- </li></ul><ul><li>command | command2 </li></ul><ul><li>The output of command1 is sent to command2 as input. </li></ul><ul><li>Example:- </li></ul><ul><li>$ls | more </li></ul><ul><li>The output of the command “ls” is sent to the “more” command as input. So the directory listing of the current directory is displayed page by page . </li></ul><ul><li>$cat file1.txt | sort file1.txt |wc file1.txt </li></ul>04/23/11 UNIT-I : UNIX Introduction

65.
<ul><li>REDIRECTION :- </li></ul><ul><li>UNIX treats the keyboard as the standard input (value 0) and terminal screen as standard output (value 1) as well as standard error (value 2). However , input can be taken from sources other than the keyboard and output can be passed to any source other than the terminal screen. such a process is called “redirection”. </li></ul><ul><li>1.Redirecting inputs </li></ul><ul><li>2.Redirecting outputs </li></ul><ul><li>3.Redirecting Error messages </li></ul><ul><li>1.Redirecting inputs :- </li></ul><ul><li>The ‘<‘ symbol is used to redirect inputs. </li></ul><ul><li>Example:- $cat < file1.txt </li></ul><ul><li>then the file1.txt is taken as input for the command – cat </li></ul><ul><li>2.Redirecting outputs:- </li></ul><ul><li>The “>” symbol is used to redirect outputs. </li></ul><ul><li>Example:- $ls > list.doc </li></ul><ul><li>Then the output of the command ‘ls’ is stored on the file “list.doc”. We can also use </li></ul><ul><li>‘ 1>’ instead of ‘>’. </li></ul><ul><li>3.Redirecting Error Messages:- </li></ul><ul><li>The ‘2>’ symbol is used to redirect error messages. </li></ul><ul><li>Example :- $cat list1.doc </li></ul><ul><li>If there is no file named “list1.doc” in the current directory , then the error message is sent to the standard error device. We can redirect this error messages using ‘2>’ symbol. </li></ul><ul><li>Example:- $cat list1.doc 2> error.txt </li></ul><ul><li>Then the error messages , if generated , will be stored on the disk – error.txt. </li></ul>04/23/11 UNIT-I : UNIX Introduction

66.
<ul><li>FILTERS:- </li></ul><ul><li>There are some UNIX commands that accept input from standard input or files , perform some manipulation on it , and produces some output to the standard output. Since these commands perform some filtering operations on data , they are appropriately called as “Filters”. These filters are used to display the contents of a file in stored order , extract the lines of a specified file that contains a specific pattern etc. </li></ul><ul><li>sort :- </li></ul><ul><ul><li>This command sorts the contents of a given file based on ASCII values of characters. </li></ul></ul><ul><ul><li>Syntax:- </li></ul></ul><ul><ul><li>sort [-option] <filename> </li></ul></ul><ul><li>Options </li></ul><ul><li>-m <filelist> =Merge sorted files specified in <filelist> </li></ul><ul><li>-o <filename> =stores output in the specified <filename> </li></ul><ul><li>-r = Sorts the contents in reverse order. </li></ul><ul><li>-u = Removes duplicate lines and display sorted content. </li></ul><ul><li>-c= Checks if the file is sorted or not. </li></ul><ul><li>Example:-$cat file.txt $sort file.txt </li></ul><ul><li> E A </li></ul><ul><li>S E </li></ul><ul><li>A S </li></ul><ul><li>W W </li></ul>04/23/11 UNIT-I : UNIX Introduction

67.
<ul><li>2. grep [Global Regular Expression Printing] :- </li></ul><ul><ul><li>This command is used to search for a specified pattern form a specified file and display those lines containing the patter. </li></ul></ul><ul><ul><li>Syntax:- </li></ul></ul><ul><ul><li>grep [-option] pattern <filename> </li></ul></ul><ul><ul><li>Where options </li></ul></ul><ul><ul><li>-b ignores spaces , tab. </li></ul></ul><ul><ul><li>-i Ignore case </li></ul></ul><ul><ul><li>-v Displays only the lines that do not match the specified pattern. </li></ul></ul><ul><ul><li>-e Displays the total number of occurrences of the pattern in the file. </li></ul></ul><ul><ul><li>-n Displays the resultant lines along with their line number. </li></ul></ul><ul><ul><li>Example:- </li></ul></ul><ul><ul><li>$cat emp.ext </li></ul></ul><ul><ul><li>1001 Ram Computer CS </li></ul></ul><ul><ul><li>1002 Merry Electronics ET </li></ul></ul><ul><ul><li>1003 John Computer CS </li></ul></ul>04/23/11 UNIT-I : UNIX Introduction

68.
<ul><li>$grep “CS” emp.txt </li></ul><ul><li>o/p:- 1001 Ram Computer CS </li></ul><ul><li>1003 John Computer CS </li></ul><ul><li>Regular Expression Character Set </li></ul><ul><li>*: Represents any number of characters </li></ul><ul><li>?: Represents any single character. </li></ul><ul><li>[r1-r2]: Range </li></ul><ul><li>[^abcd] : Matches a single character which is not a,b,c or d. </li></ul><ul><li>^[character]: Matches the lines that are beginning with the character specified in <Character> </li></ul><ul><li>[character]$ :Matches the lines that are ending with the character specified in <character> </li></ul><ul><li>Example:- </li></ul><ul><li>$grep “Com*” emp.txt </li></ul><ul><li>o/p:- 1001 Ram Computer CS </li></ul><ul><li>1003 John Computer CS </li></ul>04/23/11 UNIT-I : UNIX Introduction

70.
<ul><li>3.uniq {Unique} </li></ul><ul><li>This command is used to handle duplicate line in a file . If this command is used without any option , It displays the lines by eliminating duplicate lines. </li></ul><ul><li>Syntax:- </li></ul><ul><li>uniq [-option] <filename> </li></ul><ul><li>Where options are as follows:- </li></ul><ul><li>-u ==Displays only the no –repeated lines. </li></ul><ul><li>-d ==Displays only the duplicate lines. </li></ul><ul><li>-c ==Displays each line by eliminating duplicate lines and prefixing the number of times it occurs. </li></ul><ul><li>Example:- </li></ul><ul><li>$cat abc.txt </li></ul><ul><li>abc </li></ul><ul><li>xyz </li></ul><ul><li>abc </li></ul><ul><li>pqr </li></ul><ul><li>$uniq abc.txt </li></ul><ul><li>abc </li></ul><ul><li>xyz </li></ul><ul><li>abc </li></ul><ul><li>pqr </li></ul>04/23/11 UNIT-I : UNIX Introduction

75.
<ul><li>tr [Translating Character] </li></ul><ul><li>This tr command filter manipulates individual characters in a line. More </li></ul><ul><li>specifically , it translates characters using one or two compact </li></ul><ul><li>expressions: </li></ul><ul><li>tr options expression1 expression2 standard input </li></ul><ul><li>tr takes input only from the standard input , it doesn’t take a filename as </li></ul><ul><li>argument. By default it translates each character in expression1 to its </li></ul><ul><li>mapped counterpart in expression2. The first character in the first </li></ul><ul><li>expression is replaced with the first character in the second expression </li></ul><ul><li>and similarly for the other characters. </li></ul><ul><li>1. Replace a character:- </li></ul><ul><li>$cat emp.txt </li></ul><ul><li>Output:- </li></ul><ul><li>1001 | John | Computer | CS </li></ul><ul><li>1002 | Merry | Electronics | ET </li></ul><ul><li>1003 | Ram | Computer | CS </li></ul>04/23/11 UNIT-I : UNIX Introduction

78.
<ul><li>sed [Stream Editor]:- </li></ul><ul><li>This is a multipurpose tool which combines the work of several filters. It is </li></ul><ul><li>derived from ed , the original editor. sed performs non-interactive </li></ul><ul><li>operations on a data stream – hence its name . </li></ul><ul><li>sed uses instructions to act on text. An instruction combines an address </li></ul><ul><li>for selecting lines , with an action to be taken on them as shown by the </li></ul><ul><li>syntax:- </li></ul><ul><li>sed [options]/[Edit Commands] ‘address action’ files </li></ul><ul><li>The address and action are enclosed within single quotes. Addressing in sed is done in two ways:- </li></ul><ul><li>By one or two line numbers. </li></ul><ul><li>By specifying a /- enclosed pattern which occurs in a line. </li></ul><ul><li>Where edit commands can be:- </li></ul><ul><li>i – Inserts after line </li></ul><ul><li>a – Appends after line </li></ul><ul><li>c – Changes lines </li></ul><ul><li>d – Deletes lines </li></ul><ul><li>p – Prints lines </li></ul><ul><li>q – Quits </li></ul>04/23/11 UNIT-I : UNIX Introduction

80.
<ul><li>Example6:- $sed -1 ‘/cs/p’ emp.txt </li></ul><ul><li>This command displays the lines that are containing the pattern “cs”. </li></ul><ul><li>Example7: - $sed ‘/cs/d’ emp.txt </li></ul><ul><li>This command displays the lines that are not containing the specified pattern </li></ul><ul><li>“ cs”. </li></ul><ul><li>Example8:- $sed ‘i ---------------------------------’ emp.txt </li></ul><ul><li>This command inserts the specified dash line before each line of the file </li></ul><ul><li>emp.txt. </li></ul><ul><li>Example9:- $sed ‘a --------------------------------’ emp.txt </li></ul><ul><li>This command inserts the specified dash line after each line of the file </li></ul><ul><li>emp.txt. </li></ul><ul><li>Example10:- $sed ‘3i ------------------------------- ‘ emp.txt </li></ul><ul><li>This command inserts the specified dash line before the third line of the file </li></ul><ul><li>emp.txt. </li></ul><ul><li>Example10:- $sed ‘3a ------------------------------- ‘ emp.txt </li></ul><ul><li>This command inserts the specified dash line after the third line of the file </li></ul><ul><li>emp.txt. </li></ul><ul><li>Example 11:- $sed ‘$a -----------------------------------’ emp.txt </li></ul><ul><li>This command inserts the specified dash line after the last line of the file </li></ul><ul><li>emp.txt </li></ul>04/23/11 UNIT-I : UNIX Introduction

83.
04/23/11 UNIT-I : UNIX Introduction <ul><ul><li>This editor can be invoked by typing vi at the $ prompt. If you specify a filename as an argument to vi , then the vi will edit the specified files , if it exits. </li></ul></ul><ul><ul><li>vi [<filename>] </li></ul></ul><ul><ul><li>A status line at the bottom of the screen (25th line) shows the filenames, current line and character position in the edited file. </li></ul></ul><ul><ul><li>vi + <line_number> <filename> </li></ul></ul><ul><ul><li>Edits the file specified in <filename> and places the cursor on the <line_number>th line. </li></ul></ul>

99.
04/23/11 UNIT-I : UNIX Introduction <ul><ul><li>Insert Mode :- </li></ul></ul><ul><ul><li>1) The text should be entered in this mode and any key press in this mode is treated as text. </li></ul></ul><ul><ul><li>2) We can enter into this mode from command mode by pressing any of the keys: </li></ul></ul><ul><ul><li>i I </li></ul></ul><ul><ul><li>a A </li></ul></ul><ul><ul><li>o O </li></ul></ul><ul><ul><li>r R </li></ul></ul><ul><ul><li>s S </li></ul></ul>

100.
04/23/11 UNIT-I : UNIX Introduction <ul><ul><li>Command Mode:- </li></ul></ul><ul><ul><li>It is the default mode when we start up vi-editor. </li></ul></ul><ul><ul><li>All the commands on vi-editor (Cursor movement text manipulation etc. ) should be used in this mode. </li></ul></ul><ul><ul><li>We can enter into this mode from insert mode by pressing the [Esc] key and from Ex Mode by pressing [Enter Key]. </li></ul></ul><ul><ul><li>Ex Command Mode:- </li></ul></ul><ul><ul><li>1. The Ex command mode (Saving files , find , replace etc ..) can be entered at the last line of the screen in this mode. </li></ul></ul><ul><ul><li>2)We can enter into this mode from command mode by pressing [:] key. </li></ul></ul>

101.
04/23/11 UNIT-I : UNIX Introduction <ul><ul><li>Insert Commands </li></ul></ul><ul><ul><li>i Inserts before cursor. </li></ul></ul><ul><ul><li>I Inserts at the beginning of the current line. </li></ul></ul><ul><ul><li>a Appends at the end of the current line. </li></ul></ul><ul><ul><li>A Appends at the start of the current line. </li></ul></ul><ul><ul><li>o Inserts a blank line below the current line. </li></ul></ul><ul><ul><li>O Inserts a blank line above the current line. </li></ul></ul>

102.
04/23/11 UNIT-I : UNIX Introduction <ul><ul><li>Delete Commands </li></ul></ul><ul><ul><li>x -Deletes a character at the cursor position. </li></ul></ul><ul><ul><li><n>x-Deletes specified number (n) of character. </li></ul></ul><ul><ul><li>X -Deletes a character before the cursor position. </li></ul></ul><ul><ul><li><n>X -Deletes specified number (n) of characters before the cursor position. </li></ul></ul><ul><ul><li>dw -Deletes from current position to end of the current word. </li></ul></ul><ul><ul><li>db -Deletes from cursor position to beginning of current word. </li></ul></ul><ul><ul><li>dd -Deletes current line. </li></ul></ul><ul><ul><li><n>dd -Deletes specified number of lines (n) from the current line. </li></ul></ul>

103.
04/23/11 UNIT-I : UNIX Introduction <ul><ul><li>Replace Commands </li></ul></ul><ul><ul><li>r – Replaces single character at the cursor position. </li></ul></ul><ul><ul><li>R –Replaces characters until[ESC] key is pressed from current cursor position. </li></ul></ul><ul><ul><li>s – Replaces single character at the cursor position with any number of character. </li></ul></ul><ul><ul><li>S – Replaces entire line. </li></ul></ul><ul><ul><li>Search Commands </li></ul></ul><ul><ul><li>/string [Enter] – Searches the specified string forward in the file. </li></ul></ul><ul><ul><li>?string [Enter]- Searches the specified string backward in the file. </li></ul></ul><ul><ul><li>n - Finds the next string in the same direction. </li></ul></ul><ul><ul><li>N - Finds the next string in the opposite direction. </li></ul></ul>

104.
04/23/11 UNIT-I : UNIX Introduction <ul><ul><li>Yanking (Copy & Paste) Commands </li></ul></ul><ul><ul><li>yy or (y) : Yanks the current line into the buffer (Copy). </li></ul></ul><ul><ul><li>nyy or ny : Copies the ‘n’ lines from the current line to the buffer. </li></ul></ul><ul><ul><li>p : Paste the yanked text below the current line. </li></ul></ul><ul><ul><li>P : Paste the yanked text above the current line. </li></ul></ul><ul><ul><li>Ex Mode Commands </li></ul></ul><ul><ul><li>:w – Saves file without quitting </li></ul></ul><ul><ul><li>:w <filename> - Saves the content into a file specified in <filename> </li></ul></ul><ul><ul><li>:x or :wq – Saves file and quits from vi. </li></ul></ul><ul><ul><li>:q! – Quits from vi without saving. </li></ul></ul>

105.
04/23/11 UNIT-I : UNIX Introduction <ul><ul><li>SET Commands </li></ul></ul><ul><ul><li>The two set command i.e. set nu and set ic. </li></ul></ul><ul><ul><li>The first is used to associate line numbers with the file . You are currently working with . </li></ul></ul><ul><ul><li>The second is used to ignore the case while searching a pattern in the file. </li></ul></ul><ul><ul><li>In addition to those two there are several other options that the user can set to customize the environment of vi. </li></ul></ul><ul><ul><li>To get a list of all the options available with set , use the command: </li></ul></ul><ul><ul><li>(ESC): set all </li></ul></ul><ul><ul><li>Thought the list is long there are only a few which are most commonly used . </li></ul></ul>

106.
04/23/11 UNIT-I : UNIX Introduction <ul><ul><li>A list of these along with the affect of each is shown in figure:- </li></ul></ul><ul><ul><li>:set nu Set display of line numbers on. </li></ul></ul><ul><ul><li>:set nonu Set display of line numbers off (Default). </li></ul></ul><ul><ul><li>:set eb Beep the speaker when an error occurs (Default). </li></ul></ul><ul><ul><li>:set noeb Do not Beep the speaker when an error occurs. </li></ul></ul><ul><ul><li>:set ai Set auto indent on. </li></ul></ul><ul><ul><li>:set noai Set auto indent off (default). </li></ul></ul><ul><ul><li>:set ic Ignores case while searching a pattern. </li></ul></ul><ul><ul><li>:set noic Do not Ignores case while searching a pattern (default). </li></ul></ul>

107.
04/23/11 UNIT-I : UNIX Introduction <ul><ul><li>.exrc Profile and Miscellaneous Commands </li></ul></ul><ul><ul><li>Type :To </li></ul></ul><ul><ul><li>Ctrl-g s how line number of current line. </li></ul></ul><ul><ul><li>Ctrl-l redraw the entire display . </li></ul></ul><ul><ul><li>:!sh fork a shell. </li></ul></ul><ul><ul><li>:type Ctrl-d to get back to vi. </li></ul></ul><ul><ul><li>. repeat last text change command at current cursor position. </li></ul></ul><ul><ul><li>:set showmode s how when you are in insert mode . </li></ul></ul><ul><ul><li>:set ic ignore case when searching. </li></ul></ul><ul><ul><li>:set noic turn ignore case off. </li></ul></ul><ul><ul><li>:set nu turn on line numbering. </li></ul></ul><ul><ul><li>:set nonu turn line numbering off. </li></ul></ul><ul><ul><li>NOTE:- </li></ul></ul><ul><ul><li>Place the :set commands in an executable file in your home directory named ~/.exrc to automatically turn on these features for every vi edit session. </li></ul></ul>