SlideShare a Scribd company logo
04/23/11 UNIT-I : UNIX Introduction
04/23/11 UNIT-I : UNIX Introduction
Unix(introduction)
04/23/11 UNIT-I : UNIX Introduction  History of UNIX 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. 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. In 1980 , BSD 4.1 (Berkelely Software Development ) was developed. In 1983, SunOs , BSD 4.2 , System were released. In 1983 , AT&T and Sun Microsystems jointly developed System V Release 4 (SVR 4). This was later developed in UNIX ware and Solaris 2.
04/23/11 UNIT-I : UNIX Introduction
04/23/11 UNIT-I : UNIX Introduction
04/23/11 UNIT-I : UNIX Introduction
 
 
 
04/23/11 UNIT-I : UNIX Introduction
04/23/11 UNIT-I : UNIX Introduction
Boot Block :-  This block contain a small boot program and partition table. 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. This is mainly what it contains:- The size of the file system. The block size used by the file system. The number of free data blocks available and a partial list of immediately allocable free data blocks. Number of free inodes available and a partial list of immediately usable inodes. Last time of updating. The state of the file system (Whether “clean “ or “dirty”). Inode Block :- This region contains the inode for every file of the file system. Data Block:- All data and programs created by users reside in this area. 04/23/11 UNIT-I : UNIX Introduction
04/23/11 UNIT-I : UNIX Introduction
Unix is a operating system, used by most large, powerful computers. 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.   The general format of a command is :- command  -options  command_arguments 04/23/11 UNIT-I : UNIX Introduction
04/23/11 UNIT-I : UNIX Introduction
1.ls(list)-To shows the list of files and direrctories. Syntax: ls [-option] [name of file name/ directory name] Where  Option Description -x Multicolumnar Output -F Marks executables with *,directories with /, and symbolic links with  @ -a Shows all filenames beginning with a dot including . And .. -R Recursive list (Directory., Subdirectory., files) -r Sorts filename in reverse order -1 One filename in each line -l long listing (Seven attributes of a file) -d dirname Lists only dirname if dirname is a directory -t Sorts filenames by last modification time -lt Sorts listing by last modification time -u Sorts filename by last access time -lu Sorts by ASCII collating sequence but listing shows last access  time -lut As above but sorted by last access time -i Displays inode number 04/23/11 UNIT-I : UNIX Introduction
$ls xyz, pqr, abc , MCA4 $ls –l Total 72 -rw-r—r–  1 kumar  metal  19514  May 10 13:54 MCA4 -rw-xr-r-  1 kumar  metal  4174  May 10 15:01 xyz drwxr-xr-x  2 kumar  meatl  84  Feb  12 12:30 pqr  $ls –li Total 72 9045 -rw-r—r–  1 kumar  metal  19514  May 10 13:54 MCA4 9056 -rw-xr-r-  1 kumar  metal  4174  May 10 15:01 xyz 9045 drwxr-xr-x  2 kumar  meatl  84  Feb  12 12:30 pqr  04/23/11 UNIT-I : UNIX Introduction
‘ *’ Represents any number of characters. ‘ ?’Represents a single character. ‘ [RANGE]’Represents character list. ‘ [Character_List]’ Matches any  single character, Which is specified in Character List. ‘ [!Character_list]’ Matches any  single character , Which is not specified in Character List. Example:- $ls pgm* 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. $ls *s This command will display all the filenames of the current directory , which are ending with “s”. $ls ?gms This command will display four character filenames, which are ending with “gms” starting with any of the allowed character.  $ls gms? This command will display four character filenames, which are starting with “gms” ending with any of the single character. 04/23/11 UNIT-I : UNIX Introduction
“ []”  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. $ls pgm[1-5]  This command will list only the files named , pgm1 , pgm2 , pgm3 , pgm4 , pgm5 if they exist in the current directory. $ls pgm[1-5],[11-15] 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. $ls a[bc]d This command will list only the files named abd and acd  $ls a[!bc]d This commands will list only the files named agd , ahd , akd , amd except abd and acd. 04/23/11 UNIT-I : UNIX Introduction
2.mkdir[Make Directory] This command is used to create new directory. General format is :- mkdir [-p] <directory-name1> <directory-name2> The option –p is used to create consequences of directories using a single mkdir command. Example:- $mkdir ibr This command will create ‘ibr’ a subdirectory of the  current directory. $mkdir x x/y  This command will create x as a subdirectory of current working directory , y as subdirectory of x. $mkdir ibr/ib/i This command will make a directory i as a subdirectory of ibr/ib, but the directory structure –ibr/ib must exist. $mkdir –p ibr/ib/i 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. 04/23/11 UNIT-I : UNIX Introduction
3.rmdir[Remove Directory] This command is used to remove (delete) the specified directory. A directory should be empty before removing it. Syntax:- rmdir [-p] <directory_name1> <directory_name2> The option –p is used to remove consequence of directories using a single rmdir command. Example:- $rmdir ibr This command will remove the directory ibr , which is the subdirectory of the current directory. $rmdir ibr/ib/i This command will remove the directory i only. $rmdir –p ibr/ib/i This commad will remove the directory i , ib and ibr consequently. 04/23/11 UNIT-I : UNIX Introduction
4.cd[Change Directory] This command is used to change working directory to a specified directory. Syntax:-  cd <existing_directory_name> Example:-  cd /home/ibr Then the directory /home/ibr becomes as the current working directory. 5.pwd[Present Working Directory / Print Working Directory] This command displays the full pathname for the current working directory. Example :- $pwd Output:- /home/bmi Your present working directory is /home/bmi. 04/23/11 UNIT-I : UNIX Introduction
5. Find 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.  Syntax:- find <path_list>  <selection _criteria>  action This is how find operators: First , it recursively examines all files in the directories specified in  path_list. It  matches each file for one or more  selection_criteria. Finally , it takes some  action  on those selected files. Example:- $find / -name a.out –print Output:- /home/kumar/scripts/a.out /home/tiwari/scripts/reports/a.out /home/sharma/a.out 04/23/11 UNIT-I : UNIX Introduction
<Selection_Criteria> 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.
Example:- $find /home/ibrahim –name “*.java” –print $find /home/ibrahim –mtime 5 –print $find /home/ibrahim –mtime +5 –print $find /home/ibrahim –mtime -5 -print 04/23/11 UNIT-I : UNIX Introduction
6. du [Disk Usage] This command reports the disk spaces that are consumed by the files ina  specified directory . Including all its subdirectories. Syntax:- du [-option]  [<directory_name /file_name>] Options Description -a  Displays counts for all files . Not just directories. -b Displays size in bytes. -c Displays output along with grand total of all arguments. -k Displays the size in Kilobytes. -m Displays the size in Megabytes. Example:-  $du  o/p :- ? $du /home/bmi/text Output:- 12 /home/bmi/text $du –a /home/bmi/text Output:- 4 /home/bmi/text/x.txt 4 /home/bmi/text/y.txt   12 /home/bmi/text 04/23/11 UNIT-I : UNIX Introduction
7.df (Disk Free) This df command reports the available free space on the mounted file system or disks. Syntax:-   df [-option] Options  Description   -l Shows local file system only   -k Displays the size in kilobytes   -m Displays the size in Megabytes   -i Reports free used percentage of used inode. This command reports the free space in blocks. Generally one block in 512 bytes. The i-nodes entry indicates that up to the specified number of files can be created on the file. Example:-  $df 04/23/11 UNIT-I : UNIX Introduction  File System 1-Blocks Used Available Used Mounted  On /dev/hda8 1612808 63632 1467248 5% / /dev/hda8 23302 3489 18610 16% /boot /dev/hda9 1035660 7100 975952 1% /home /dev/hda10 1778840 742916 945560 44% /usr /dev/hda11 1517920 1517920 1423784 2% /var
1.cat :- Means Concatenate i.e. To add more than one string. 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 . cat command provides the various facility in UNIX Operating System. This various facility is also called various flavors of cat command.  04/23/11 UNIT-I : UNIX Introduction
04/23/11 UNIT-I : UNIX Introduction
04/23/11 UNIT-I : UNIX Introduction
04/23/11 UNIT-I : UNIX Introduction
04/23/11 UNIT-I : UNIX Introduction
04/23/11 UNIT-I : UNIX Introduction
04/23/11 UNIT-I : UNIX Introduction
04/23/11 UNIT-I : UNIX Introduction
2.cp [Copy]:-  This command is used to copy the content of one file into another. If the destination is an existing file , the file is overwritten . If the destination is an existing directory the file is copied into that directory. Syntax:- cp [-option] <source_file> < destination_file> where options can be:- i  – prompt before overwritten destination files. p - Preserve all information ,including owner , group , permission and timestamps. R - Recursively copies files in all subdirectories. Example:-   $cp myfile myfile1 Output:- $cat myfile I am file one. $cat myfile1 I am file one.  04/23/11 UNIT-I : UNIX Introduction
3. rm [Remove]:- 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. Syntax:- rm [-option] <filename> where options are as follows:- r - deletes all directories including the lower order directories. Recursively deletes entire contents    of the specified directory and the directory itself . i - Prompts before deleting f - Removes write – protected files also, without prompting. Example:- $rm myfile1 This command deletes the file myfile form the current directory. $rm –f /usr/ibrahim This command deletes all the files and subdirectories of the specified directory /usr/ibrahim. Note that the directory ‘ibrahim’ also will be delted. 04/23/11 UNIT-I : UNIX Introduction
4.mv [Move] This command is used to remove the specified files / directories. Syntax:- $mv <source> <destination> Example:- mv file1.txt  file2.txt Output:- $cat file1.txt File Not Found $cat file2.txt I am file1. 04/23/11 UNIT-I : UNIX Introduction
5. wc [Word Count] This  command is used to display the number of lines,words and characters of information stored on the specified file. Syntax:- wc  [-option] <File_Name> Where l  - Displays the number of lines in the file w  – Displays the number of words in the file c  – Display the number of characters in the file Examples:-  Command Output $cat  file1 I am file1 $wc file1 1  3  10  file1 $wc  –l file1 1  file1 $wc  –w file1 3  file1 $wc  –c file1 10  file1 04/23/11 UNIT-I : UNIX Introduction
6.ln(Link) 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. Syntax:- ln <filename> <additional_filename> 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. Example:- $ls –l test1.txt -rw-rw-r-- 1  bmi bmi  75  jan 13  14:35  test1.txt $ln test1.txt test2.txt $ls –l test*.txt -rw-rw-r-- 2  bmi bmi  75  jan 13  14:35  test1.txt -rw-rw-r-- 2  bmi bmi  75  jan 13  14:35  test2.txt  $rm test1.txt $ls –l test2.txt -rw-rw-r-- 1  bmi bmi  75  jan 13  14:35  test2.txt  04/23/11 UNIT-I : UNIX Introduction
7.file This command lists the general classification of a specified file. It lets you to know if the contents of the specified file is ASCII text , C program text , directory and others. Syntax:-  file <filename> Example:- $file test1.txt Output test1.txt : ASCII text. $file * Output test1.test: ASCII text xyz: Directory 04/23/11 UNIT-I : UNIX Introduction
8.cmp [Compare] This command is used compare two files. Syntax:-  cmp  <filename1> <filename2> This command reports the first instance of differences between the specified files. That is the two files are compared byte by byte and the location of the first mismatch is echoed to the screen. Example:- $cat file1.txt I am Ram What is your name? $cat file2.txt I am Ram What are you doing? $cmp file1.txt file2.txt Output file1.txt file2.txt  differ  : byte 10  char 1, line2 04/23/11 UNIT-I : UNIX Introduction
9. comm [Common] This command uses two sorted files as argumnets and reports what is common.It compares each line of the first with its corresponding line in the second file. The output of this command is in three column as follows: Column1 : Contains lines common for both filename 1 and filename2  Column2 : Contains lines unique to filename2. Column3 : Contains lines unique to filename1. Syntax:-  comm [-option] <filename1> <filename2> Option:- 1 - Suppresses  listing of column1 2 - Suppresses listing of column2 3 - Suppresses listing Example:- $cat file1.txt $cat file2.txt I am Ram I am Ram What is your name? What are you doing? $comm file1.txt  file2.txt Output:- I am Ram   What are you doing?   What is your name? 04/23/11 UNIT-I : UNIX Introduction
10. nl [ Non-Blank Line] This command numbers all non-blank line in the specified text file and display the same on the screen.  Syntax:-  nl  <filename> Example:- $cat file1.txt I am Ram What is your name? $nl file1.txt Output:- 1 I am Ram 2 What is your name? 04/23/11 UNIT-I : UNIX Introduction
11. tac  This command reverses a file contents , so that the last line becomes the first line.  Syntax:-  tac  <filename> Example:- $cat file1.txt I am Ram What is your name? $tac file1.txt Output:- What is your name?   I am Ram  04/23/11 UNIT-I : UNIX Introduction
12. tail This command displays the end of the specified file.  Syntax:-  tail -n  <filename> Example:- $cat student.txt Mohan always keeps himself to himself. We were in a hurry. The road being zigzag , We had to cut off a corner to reach in time. In his youth , he was practically rolling in money. $tail -1 file1.txt Output:-   In his youth , he was practically rolling in money. $tail -2 file1.txt Output:- We had to cut off a corner to reach in time. In his youth , he was practically rolling in money. 04/23/11 UNIT-I : UNIX Introduction
12. head This command displays the top of the specified file.  Syntax:-  head -n  <filename> Example:- $cat student.txt Mohan always keeps himself to himself. We were in a hurry. The road being zigzag , We had to cut off a corner to reach in time. In his youth , he was practically rolling in money. $head -1 file1.txt Output:-   Mohan always keeps himself to himself.   $tail -2 file1.txt Output:- Mohan always keeps himself to himself. We were in a hurry. The road being zigzag , 04/23/11 UNIT-I : UNIX Introduction
UNIX treats everything as files.There are 3 types of files in UNIX as follows:- 1.Ordinary File 2.Directory File 3.Special File There are 3 types of modes for accessing these files as follows:- 1. Read Mode(r) 2.Write Mode(w) 3.Execute Mode(x) Unix separates its users into 3 groups for securty and convenience as follows :- 1. user (u) 2. user group(g) 3. others(o) 04/23/11 UNIT-I : UNIX Introduction
13. chmod [ Change Mode] This command is used to change the file permissions for an existing file. We can use any one of the symbolic and octal notations to change file permissions. Syntax:-  chmod <user_symbols set/deny_symbol access_symbol >  <filename> 14 chgrp[Change Group] This command is used to change the group ownership of specified file. Syntax:- chgrp <new_group name> <filename> 15.chown [Change Owner] This command is used to change the owner of a specified file. Syntax:- chown <new_owner> <filename> 04/23/11 UNIT-I : UNIX Introduction
04/23/11 UNIT-I : UNIX Introduction
04/23/11 UNIT-I : UNIX Introduction  1.date :-  This command displays the  current system date. Syntax:- date + <format> %H Hour 00 to 23 %I Hour 00 to 12 %M Minute 00 to 59 %S Second 00 to 59 %D Date MM/DD/YY %T Time HH:MM:SS %w (SMALL) Day of the Week %r Time in AM & PM %y Last two digits of the  year
04/23/11 UNIT-I : UNIX Introduction  Command Output $date MON  JAN  07  15:10:10  IST  2008 $date  +%H 15 $date +%I 03 $date +%M 10 $date +%w 2  (0-Sunday , 1-Monday , 2-Tuesday , 3-Wednesday , 4-Thursday , 5-Friday, 6-Saturday) $date +%r 03:10:10 PM
2. Who 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. Syntax & Example :- $who Output:- Aman tty1 jan  07  10:17 Shwetabh tty2 jan 07 10:20 Neha tty4 jan 07 10:30 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. 04/23/11 UNIT-I : UNIX Introduction
3. Who am I  This commands tells you who you are. (Working on the current terminal). Syntax & Example :- $who am i Output:- Aman tty1 jan  07  10:17 04/23/11 UNIT-I : UNIX Introduction
4.man (Manual) This command displays the syntax and detailed usage of the UNIX command , which is supplied as argument. Syntax :- $man <UNIX_COMMAND> Example:- $man wc This will display the help details for “wc” command. Almost all of the command offer – help option that displays a short listing of all the options. $wc --help 04/23/11 UNIT-I : UNIX Introduction
5. cal (calculator) This command will display the calender for the specified month and year. Syntax :- $cal [month] <year] where month can be ranged form 1 to 12 Example:- $cal 2008 This command will display calender for thr year 2008 (from 1 to 12 months). $cal 1 2008 This command will display the calender for the month january of the year 2008. 04/23/11 UNIT-I : UNIX Introduction
6. lpr (Line Printer) This command is used to print one or more files on printer. Syntax :- $lpr [-option] <filename1>………………..<filenamen> where options can be :- r – Removes file(s) form directory after printing. m – Mail inform you when printing is over. Example:- $lpr file1.txt 04/23/11 UNIT-I : UNIX Introduction
7. expr  This command is used to perform arithmetic operations on integer. The arithmetic operator and their corresponding functions are given below. Syntax :- + Addition - Subtraction \* Multiplication / Division [It gives my quotient of the division] % Remainder of division [ Modulas operator ]    04/23/11 UNIT-I : UNIX Introduction
8. bc [Basic Calculator] This command is used to perform arithmetic operation on integer as well as on floats (Decimal Number]. 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. Example :- Add 10 and 20  $bc 10 + 20 30 ^d 04/23/11 UNIT-I : UNIX Introduction
$bc 10 / 3 3 [Decimal portion is truncated] ^d $bc scale = 1 8 / 3 2.6 scale = 2 8 / 3 2.66 ^d 04/23/11 UNIT-I : UNIX Introduction
$bc 1. ibase = 2  ----set ibase to binary (2). 101   -----Type the input binary number. 5   -----Result in Decimal obase = 2 ----set obase to binary(2). 5 ----Type the input decimal  number 101 ----Result in Binary form ^d Here similarly for Octal and hexadecimal  numbers. 04/23/11 UNIT-I : UNIX Introduction
04/23/11 UNIT-I : UNIX Introduction
PIPE :- Pipe is a mechanism in which the output of one command can be redirected as input to another command. Syntax:- command | command2 The output of command1 is sent to command2 as input. Example:- $ls | more 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 . $cat file1.txt | sort file1.txt |wc file1.txt 04/23/11 UNIT-I : UNIX Introduction
REDIRECTION :- 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”. 1.Redirecting inputs 2.Redirecting outputs 3.Redirecting Error messages 1.Redirecting inputs :- The ‘<‘ symbol is used to redirect inputs. Example:- $cat < file1.txt then the file1.txt is taken as input for the command – cat  2.Redirecting outputs:- The “>” symbol is used to redirect outputs. Example:- $ls > list.doc Then the output of the command ‘ls’ is stored on the file “list.doc”. We can also use  ‘ 1>’ instead of ‘>’. 3.Redirecting Error Messages:- The ‘2>’ symbol is used to redirect error messages. Example :- $cat list1.doc 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. Example:-  $cat list1.doc 2> error.txt Then the error messages , if generated , will be stored on the disk – error.txt.   04/23/11 UNIT-I : UNIX Introduction
FILTERS:- 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. sort :- This command sorts the contents of a given file based on ASCII values of characters. Syntax:-  sort [-option] <filename>  Options -m  <filelist> =Merge sorted files specified in <filelist> -o <filename> =stores output in the specified <filename> -r  = Sorts the contents in reverse order. -u = Removes duplicate lines and display sorted content. -c= Checks if the file is sorted or not. Example:-$cat file.txt $sort file.txt   E A S E A S W W 04/23/11 UNIT-I : UNIX Introduction
2. grep [Global Regular Expression Printing] :- This command is used to search for a specified pattern form a specified file and display those lines containing the patter. Syntax:- grep [-option] pattern <filename> Where options  -b ignores spaces , tab. -i Ignore case  -v Displays only the lines that do not match the specified pattern. -e Displays the total number of occurrences of the pattern in the file. -n Displays the resultant lines along with their line number. Example:- $cat emp.ext 1001 Ram Computer CS 1002 Merry Electronics ET 1003 John Computer  CS 04/23/11 UNIT-I : UNIX Introduction
$grep “CS” emp.txt o/p:- 1001 Ram Computer CS 1003 John Computer CS Regular Expression Character Set *: Represents any number of characters ?: Represents any single character. [r1-r2]: Range [^abcd] : Matches a single character which is not a,b,c or d. ^[character]: Matches the lines that are beginning with the character specified in <Character> [character]$ :Matches the lines that are ending with the character specified in <character> Example:- $grep “Com*” emp.txt o/p:- 1001 Ram Computer CS 1003 John Computer CS 04/23/11 UNIT-I : UNIX Introduction
Related  commands with grep:-  1.egrep [ Extended grep] 2.fgrep  [ Fixed grep] egrep  :-  This command offers additional features than grep. Multiple patterns can be searched by using pipe symbol. 04/23/11 UNIT-I : UNIX Introduction
3.uniq {Unique} 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. Syntax:- uniq [-option] <filename> Where options are as follows:- -u ==Displays only the no –repeated lines. -d ==Displays only the duplicate lines. -c ==Displays each line by eliminating duplicate lines and prefixing the number    of times it occurs. Example:- $cat abc.txt abc xyz abc pqr $uniq abc.txt abc xyz abc pqr 04/23/11 UNIT-I : UNIX Introduction
$uniq –u abc.txt O/P:- xyz pqr $uniq –d abc.txt O/P:- abc $uniq –c abc.txt O/P:- 2   abc 1 xyz 1 pqr 04/23/11 UNIT-I : UNIX Introduction
cut :- This command is used to cut the columns/ fields of a specified file [Like the head and tail commands cut the line-rows]. Syntax:- cut [-option] <filename> Where options c <Columns> -Cuts the column specified in <columns>. You must separate the column numbers by using commas. f <Fields> - Cuts the fields specified in <fields> . You must separate field number by using commas. Example:- $cat emp.txt 1001 John Computer Cs 1002 Merry Electronics ET 1003 Ram Computer CS 04/23/11 UNIT-I : UNIX Introduction
$cut –c 2-5, 11-15 emp.txt Output:- 001 Compu  002 Elec 003 Comp $cut -f 2,3 emp.txt Output:- John Computer Merry Electronics Ram Computer $cut –d “|” –f 1,3- emp.txt 1001 Computer  CS 1002 Electronics ET 1003 Computer  CS $cut –f 1-3 emp.txt Output:- 1001 John Computer 1002 Merry Electronics 1003 Ram Computer 04/23/11 UNIT-I : UNIX Introduction
paste:- This command concatenate the contents of the specified files into to a  single file vertically. [Cut command separates the columns , this paste  command merges the columns]. Syntax:- paste <Filename1> <filename2>………<filename n> Example:- $cat e1.txt $cat e2.txt 1001 1004 1002 1005 1003 1006 $paste e1.txt e2.txt Output:- 1001 1002 1003 1004 1005 1006 04/23/11 UNIT-I : UNIX Introduction
tr [Translating Character] This tr command  filter manipulates individual characters in a line. More  specifically , it translates characters using one or two compact  expressions: tr options expression1 expression2 standard input  tr takes input only from the standard input , it doesn’t take a filename as argument. By default  it translates each character in expression1 to its  mapped counterpart in expression2. The first character in the first  expression is replaced with the first character in the second expression  and similarly for the other characters.  1. Replace a character:- $cat emp.txt Output:- 1001 | John  | Computer  | CS 1002 | Merry | Electronics | ET 1003 | Ram  | Computer  | CS 04/23/11 UNIT-I : UNIX Introduction
$tr ‘|’ ‘-’ emp.txt  Output:- 1001 - John  - Computer  - CS 1002 - Merry - Electronics - ET 1003 - Ram  - Computer  - CS 2. Changing Case a Text   $cat emp.txt | tr ‘[a-z]’ ‘[A-Z]’ Output:- 1001 | JOHN  | COMPUTER  | CS 1002 | MERRY |ELECTRONICS | ET 1003 | RAM  | COMPUTER  |CS $cat emp.txt | tr ‘C,p’ ‘c,P’  Output:- 1001 | John  | comPuter  | cS 1002 | Merry | Electronics | ET 1003 | Ram  | comPuter  | CS 04/23/11 UNIT-I : UNIX Introduction
3. Deleting Characters (-d):- $cat emp.txt Output:- 1001| John  | Computer  | CS 1002| Merry | Electronics | ET 1003| Ram  | Computer  | CS $tr –d ‘|’ emp.txt Output:- 1001 John  Computer  CS 1002 Merry  Electronics  ET 1003 Ram  Computer  CS 04/23/11 UNIT-I : UNIX Introduction
sed [Stream Editor]:- This is a multipurpose tool which combines the work of several filters. It is derived from ed , the original editor. sed performs non-interactive  operations on a data stream – hence its name .  sed uses instructions to act on text. An instruction combines an address  for selecting lines , with an action to be taken on them as shown by the  syntax:- sed [options]/[Edit Commands] ‘address action’ files The address and action are enclosed within single quotes. Addressing in sed is done in two ways:- By one or two line numbers. By specifying a /- enclosed pattern which occurs in a line.  Where edit commands can be:- i  – Inserts after line a – Appends after line c – Changes lines d – Deletes lines p – Prints lines q – Quits 04/23/11 UNIT-I : UNIX Introduction
Example1:-$sed ‘2q’ emp.txt Output:- 1001 John Computer  CS 1002 Merry Electronics ET This command displays the 1 st  two lines of the emp.txt file. Example2:- $sed ‘2d’ emp.txt Output:- 1001 John Computer  CS 1003 Ram Computer  CS This command displays the contents of emp.txt by deleting the second line. Example3:- $sed –n ‘2p’ emp.txt Output:- 1002 Merry Electronics ET This command displays the second line of the emp.txt. Example4:- $sed –n ‘2,4p’ emp.txt This command displays the lines 2 through 4 of emp.txt. Example5:- $sed –n ‘$p’ e mp.txt This command displays the last line of emp.txt. 04/23/11 UNIT-I : UNIX Introduction
Example6:- $sed -1 ‘/cs/p’ emp.txt This command displays the lines that are containing the pattern “cs”. Example7: - $sed ‘/cs/d’ emp.txt This command displays the lines that are not containing the specified pattern “ cs”. Example8:- $sed ‘i\ ---------------------------------’ emp.txt This command inserts the specified dash line before each line of the file emp.txt. Example9:- $sed ‘a\ --------------------------------’ emp.txt This command inserts the specified dash line after each line of the file emp.txt. Example10:- $sed ‘3i\ ------------------------------- ‘ emp.txt This command inserts the specified dash line before the third line of the file  emp.txt. Example10:- $sed ‘3a\ ------------------------------- ‘ emp.txt This command inserts the specified dash line after the third line of the file  emp.txt. Example 11:- $sed ‘$a\  -----------------------------------’ emp.txt This command inserts the specified dash line after the last line of the file  emp.txt 04/23/11 UNIT-I : UNIX Introduction
04/23/11 UNIT-I : UNIX Introduction  yacc - yet another compiler-compiler The yacc command converts a context-free grammar into a set of tables .The lex command is useful for creating lexical analyzers usable by yacc.
04/23/11 UNIT-I : UNIX Introduction
04/23/11 UNIT-I : UNIX Introduction  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. vi [<filename>] A status line at the bottom of the screen (25th line) shows the filenames, current line and character position in the edited file. vi + <line_number> <filename> Edits the file specified in <filename> and places the cursor on the <line_number>th line.
04/23/11 UNIT-I : UNIX Introduction  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccccccccccc ddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeee ~ ~ ~ ~ ~ ~ ~ :wq
04/23/11 UNIT-I : UNIX Introduction  vi Modes Insert/Input Mode Command Mode Ex-Mode
 
 
 
 
 
 
 
 
 
 
 
 
04/23/11 UNIT-I : UNIX Introduction  Input Mode Ex-Mode Command  Mode Shell vi foo :x, :q :wq & ZZ [Enter] : [Esc] i,I,a,A,o,O,r,R,s, and S  T H E T H R E E M O D E S
04/23/11 UNIT-I : UNIX Introduction  Insert Mode :- 1) The text should be entered in this mode and any  key press in this mode is treated as text. 2) We can enter into this mode from command mode  by pressing any of the keys: i  I a A o O r R s S
04/23/11 UNIT-I : UNIX Introduction  Command Mode:- It is the default mode when we start up vi-editor. All the commands on vi-editor (Cursor movement text manipulation  etc. ) should be used in this mode. We can enter into this mode from insert mode by pressing the [Esc]  key and from Ex Mode by pressing  [Enter Key]. Ex Command Mode:- 1. The Ex command mode (Saving files , find , replace etc ..)  can be  entered at the last line of the screen in this mode. 2)We can enter into this mode from command mode by pressing [:]  key.
04/23/11 UNIT-I : UNIX Introduction  Insert Commands i Inserts before cursor. I Inserts at the beginning of the current line. a Appends at the end of the current line. A Appends at the start of the current line. o Inserts a blank line below the current line. O Inserts a blank line above the current line.
04/23/11 UNIT-I : UNIX Introduction  Delete Commands x -Deletes a character at the cursor position. <n>x-Deletes specified number (n) of character. X  -Deletes a character before the cursor position. <n>X  -Deletes specified number (n) of characters before the    cursor position. dw  -Deletes from current position to end of the      current word. db  -Deletes from cursor position to beginning of      current word. dd  -Deletes current line. <n>dd -Deletes specified number of lines (n) from the      current line.
04/23/11 UNIT-I : UNIX Introduction  Replace  Commands r – Replaces single character at the cursor position. R –Replaces characters until[ESC] key is pressed from current    cursor position. s – Replaces single character at the cursor position with any    number of character. S – Replaces entire line. Search Commands /string [Enter] – Searches the specified string forward in the  file. ?string [Enter]- Searches the specified string backward in the    file. n   -  Finds the next string in the same direction. N   -  Finds the next string in the opposite direction.
04/23/11 UNIT-I : UNIX Introduction  Yanking (Copy & Paste) Commands yy or (y)  : Yanks the current line into the buffer (Copy). nyy or ny  : Copies the ‘n’ lines from the current line to the    buffer. p   : Paste the yanked text below the current line. P   : Paste the yanked text above the current line. Ex Mode  Commands :w  – Saves file without quitting :w <filename> - Saves the content into a file specified in    <filename> :x or :wq  – Saves file and quits from vi. :q!  – Quits from vi without saving.
04/23/11 UNIT-I : UNIX Introduction  SET  Commands The two set command i.e. set nu and set ic. The first is used to associate line numbers with the file . You are currently working with . The second is used to ignore the case while searching a pattern in the file. In addition to those two there are several other options that the user can set to customize the environment of vi. To get a list of all the options available with set , use the command:  (ESC): set all Thought the list is long there are only a few which are most commonly used .
04/23/11 UNIT-I : UNIX Introduction  A list of these along with the  affect of each is shown in figure:- :set nu  Set display of line numbers on. :set nonu Set display of line numbers off (Default). :set eb Beep the speaker when an error occurs (Default). :set noeb Do not Beep the speaker when an error occurs.  :set ai Set auto indent on. :set noai Set auto indent off (default). :set ic Ignores case while searching a pattern. :set noic Do not Ignores case while searching a pattern  (default).
04/23/11 UNIT-I : UNIX Introduction  .exrc Profile and Miscellaneous Commands Type :To Ctrl-g s how line number of current line. Ctrl-l redraw the entire display . :!sh fork a shell. :type Ctrl-d  to get back to vi. . repeat last text change command at current  cursor position. :set showmode s how when you are in insert mode . :set ic ignore case when searching. :set noic turn ignore case off. :set nu turn on line numbering. :set nonu turn line numbering off. NOTE:- 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.

More Related Content

PDF
Unix Command Line Productivity Tips
PPTX
Unix slideshare
PPTX
Know the UNIX Commands
PPT
Basic Unix
PDF
PPT
Unix/Linux Basic Commands and Shell Script
PPTX
Linux Command Suumary
PDF
Introduction to UNIX Command-Lines with examples
Unix Command Line Productivity Tips
Unix slideshare
Know the UNIX Commands
Basic Unix
Unix/Linux Basic Commands and Shell Script
Linux Command Suumary
Introduction to UNIX Command-Lines with examples

What's hot (20)

PPT
Linux Commands
PPS
QSpiders - Unix Operating Systems and Commands
PPTX
Unix Linux Commands Presentation 2013
PDF
50 most frequently used unix linux commands (with examples)
PDF
Basic linux commands
DOC
Some basic unix commands
PPTX
Unix OS & Commands
PPT
Basic Linux day 2
PPTX
Linux command for beginners
PPT
Basic 50 linus command
PPT
PDF
Useful Linux and Unix commands handbook
ODP
Linux commands
PPTX
Linux powerpoint
ODP
Linux commands
PPT
Linux basic commands
PPT
Linux Administration
PPT
Linux commands
PDF
Linux Command Line Basics
PPT
Linux commands and file structure
Linux Commands
QSpiders - Unix Operating Systems and Commands
Unix Linux Commands Presentation 2013
50 most frequently used unix linux commands (with examples)
Basic linux commands
Some basic unix commands
Unix OS & Commands
Basic Linux day 2
Linux command for beginners
Basic 50 linus command
Useful Linux and Unix commands handbook
Linux commands
Linux powerpoint
Linux commands
Linux basic commands
Linux Administration
Linux commands
Linux Command Line Basics
Linux commands and file structure
Ad

Viewers also liked (20)

PDF
Unix - An Introduction
PPTX
UNIX/Linux training
PPTX
Unix Operating System
PPT
Digital communication
PPTX
Unix ppt
PPTX
Unix
ODP
intro unix/linux 02
PPT
UNIX and Linux - an introduction by Mathias Homann
PPTX
UNIX Operating System
PPT
Unix memory management
PPTX
Linux ppt
PPTX
Unix operating system
PDF
Unix Training - 1
PPT
Unix Internals OS Architecture
PPTX
Unix Process management
PPTX
Unix training session 1
PDF
Perl programming language
PPTX
Server vs client
ODP
Introduction to Perl - Day 1
Unix - An Introduction
UNIX/Linux training
Unix Operating System
Digital communication
Unix ppt
Unix
intro unix/linux 02
UNIX and Linux - an introduction by Mathias Homann
UNIX Operating System
Unix memory management
Linux ppt
Unix operating system
Unix Training - 1
Unix Internals OS Architecture
Unix Process management
Unix training session 1
Perl programming language
Server vs client
Introduction to Perl - Day 1
Ad

Similar to Unix(introduction) (20)

PPTX
Basics of Unix Adminisration
PDF
Unix command
PPSX
Unix environment [autosaved]
PPTX
UNIX.pptx
PDF
Linux Notes-1.pdf
PDF
Lecture1 2 intro-unix
PPTX
2. UNIX OS System Architecture easy.pptx
PDF
AOS Lab 1: Hello, Linux!
PPTX
Chapter 2 Linux File System and net.pptx
PPTX
Rishav Mishra final presentation on UNIX Final.pptx
DOCX
Directories description
PPTX
Unix assignment help
PPT
PowerPoint_merge.ppt on unix programming
PPTX
Unix-basic-commands-operatingSystem.pptx
PPTX
465330485-Unix-basic-commands-opera.pptx
PPT
Karkha unix shell scritping
ODP
Unix tips and tricks
PDF
UNIX Command Cheat Sheets
PDF
Basics of UNIX Commands
PPT
Linux day 1
Basics of Unix Adminisration
Unix command
Unix environment [autosaved]
UNIX.pptx
Linux Notes-1.pdf
Lecture1 2 intro-unix
2. UNIX OS System Architecture easy.pptx
AOS Lab 1: Hello, Linux!
Chapter 2 Linux File System and net.pptx
Rishav Mishra final presentation on UNIX Final.pptx
Directories description
Unix assignment help
PowerPoint_merge.ppt on unix programming
Unix-basic-commands-operatingSystem.pptx
465330485-Unix-basic-commands-opera.pptx
Karkha unix shell scritping
Unix tips and tricks
UNIX Command Cheat Sheets
Basics of UNIX Commands
Linux day 1

Recently uploaded (20)

PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Institutional Correction lecture only . . .
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Lesson notes of climatology university.
PDF
RMMM.pdf make it easy to upload and study
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Classroom Observation Tools for Teachers
PPTX
Cell Structure & Organelles in detailed.
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Complications of Minimal Access Surgery at WLH
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
VCE English Exam - Section C Student Revision Booklet
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Institutional Correction lecture only . . .
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Lesson notes of climatology university.
RMMM.pdf make it easy to upload and study
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Anesthesia in Laparoscopic Surgery in India
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Microbial disease of the cardiovascular and lymphatic systems
FourierSeries-QuestionsWithAnswers(Part-A).pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Module 4: Burden of Disease Tutorial Slides S2 2025
Classroom Observation Tools for Teachers
Cell Structure & Organelles in detailed.
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Complications of Minimal Access Surgery at WLH
102 student loan defaulters named and shamed – Is someone you know on the list?
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf

Unix(introduction)

  • 1. 04/23/11 UNIT-I : UNIX Introduction
  • 2. 04/23/11 UNIT-I : UNIX Introduction
  • 4. 04/23/11 UNIT-I : UNIX Introduction History of UNIX 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. 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. In 1980 , BSD 4.1 (Berkelely Software Development ) was developed. In 1983, SunOs , BSD 4.2 , System were released. In 1983 , AT&T and Sun Microsystems jointly developed System V Release 4 (SVR 4). This was later developed in UNIX ware and Solaris 2.
  • 5. 04/23/11 UNIT-I : UNIX Introduction
  • 6. 04/23/11 UNIT-I : UNIX Introduction
  • 7. 04/23/11 UNIT-I : UNIX Introduction
  • 8.  
  • 9.  
  • 10.  
  • 11. 04/23/11 UNIT-I : UNIX Introduction
  • 12. 04/23/11 UNIT-I : UNIX Introduction
  • 13. Boot Block :- This block contain a small boot program and partition table. 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. This is mainly what it contains:- The size of the file system. The block size used by the file system. The number of free data blocks available and a partial list of immediately allocable free data blocks. Number of free inodes available and a partial list of immediately usable inodes. Last time of updating. The state of the file system (Whether “clean “ or “dirty”). Inode Block :- This region contains the inode for every file of the file system. Data Block:- All data and programs created by users reside in this area. 04/23/11 UNIT-I : UNIX Introduction
  • 14. 04/23/11 UNIT-I : UNIX Introduction
  • 15. Unix is a operating system, used by most large, powerful computers. 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. The general format of a command is :- command -options command_arguments 04/23/11 UNIT-I : UNIX Introduction
  • 16. 04/23/11 UNIT-I : UNIX Introduction
  • 17. 1.ls(list)-To shows the list of files and direrctories. Syntax: ls [-option] [name of file name/ directory name] Where Option Description -x Multicolumnar Output -F Marks executables with *,directories with /, and symbolic links with @ -a Shows all filenames beginning with a dot including . And .. -R Recursive list (Directory., Subdirectory., files) -r Sorts filename in reverse order -1 One filename in each line -l long listing (Seven attributes of a file) -d dirname Lists only dirname if dirname is a directory -t Sorts filenames by last modification time -lt Sorts listing by last modification time -u Sorts filename by last access time -lu Sorts by ASCII collating sequence but listing shows last access time -lut As above but sorted by last access time -i Displays inode number 04/23/11 UNIT-I : UNIX Introduction
  • 18. $ls xyz, pqr, abc , MCA4 $ls –l Total 72 -rw-r—r– 1 kumar metal 19514 May 10 13:54 MCA4 -rw-xr-r- 1 kumar metal 4174 May 10 15:01 xyz drwxr-xr-x 2 kumar meatl 84 Feb 12 12:30 pqr $ls –li Total 72 9045 -rw-r—r– 1 kumar metal 19514 May 10 13:54 MCA4 9056 -rw-xr-r- 1 kumar metal 4174 May 10 15:01 xyz 9045 drwxr-xr-x 2 kumar meatl 84 Feb 12 12:30 pqr 04/23/11 UNIT-I : UNIX Introduction
  • 19. ‘ *’ Represents any number of characters. ‘ ?’Represents a single character. ‘ [RANGE]’Represents character list. ‘ [Character_List]’ Matches any single character, Which is specified in Character List. ‘ [!Character_list]’ Matches any single character , Which is not specified in Character List. Example:- $ls pgm* 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. $ls *s This command will display all the filenames of the current directory , which are ending with “s”. $ls ?gms This command will display four character filenames, which are ending with “gms” starting with any of the allowed character. $ls gms? This command will display four character filenames, which are starting with “gms” ending with any of the single character. 04/23/11 UNIT-I : UNIX Introduction
  • 20. “ []” 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. $ls pgm[1-5] This command will list only the files named , pgm1 , pgm2 , pgm3 , pgm4 , pgm5 if they exist in the current directory. $ls pgm[1-5],[11-15] 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. $ls a[bc]d This command will list only the files named abd and acd $ls a[!bc]d This commands will list only the files named agd , ahd , akd , amd except abd and acd. 04/23/11 UNIT-I : UNIX Introduction
  • 21. 2.mkdir[Make Directory] This command is used to create new directory. General format is :- mkdir [-p] <directory-name1> <directory-name2> The option –p is used to create consequences of directories using a single mkdir command. Example:- $mkdir ibr This command will create ‘ibr’ a subdirectory of the current directory. $mkdir x x/y This command will create x as a subdirectory of current working directory , y as subdirectory of x. $mkdir ibr/ib/i This command will make a directory i as a subdirectory of ibr/ib, but the directory structure –ibr/ib must exist. $mkdir –p ibr/ib/i 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. 04/23/11 UNIT-I : UNIX Introduction
  • 22. 3.rmdir[Remove Directory] This command is used to remove (delete) the specified directory. A directory should be empty before removing it. Syntax:- rmdir [-p] <directory_name1> <directory_name2> The option –p is used to remove consequence of directories using a single rmdir command. Example:- $rmdir ibr This command will remove the directory ibr , which is the subdirectory of the current directory. $rmdir ibr/ib/i This command will remove the directory i only. $rmdir –p ibr/ib/i This commad will remove the directory i , ib and ibr consequently. 04/23/11 UNIT-I : UNIX Introduction
  • 23. 4.cd[Change Directory] This command is used to change working directory to a specified directory. Syntax:- cd <existing_directory_name> Example:- cd /home/ibr Then the directory /home/ibr becomes as the current working directory. 5.pwd[Present Working Directory / Print Working Directory] This command displays the full pathname for the current working directory. Example :- $pwd Output:- /home/bmi Your present working directory is /home/bmi. 04/23/11 UNIT-I : UNIX Introduction
  • 24. 5. Find 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. Syntax:- find <path_list> <selection _criteria> action This is how find operators: First , it recursively examines all files in the directories specified in path_list. It matches each file for one or more selection_criteria. Finally , it takes some action on those selected files. Example:- $find / -name a.out –print Output:- /home/kumar/scripts/a.out /home/tiwari/scripts/reports/a.out /home/sharma/a.out 04/23/11 UNIT-I : UNIX Introduction
  • 25. <Selection_Criteria> 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.
  • 26. Example:- $find /home/ibrahim –name “*.java” –print $find /home/ibrahim –mtime 5 –print $find /home/ibrahim –mtime +5 –print $find /home/ibrahim –mtime -5 -print 04/23/11 UNIT-I : UNIX Introduction
  • 27. 6. du [Disk Usage] This command reports the disk spaces that are consumed by the files ina specified directory . Including all its subdirectories. Syntax:- du [-option] [<directory_name /file_name>] Options Description -a Displays counts for all files . Not just directories. -b Displays size in bytes. -c Displays output along with grand total of all arguments. -k Displays the size in Kilobytes. -m Displays the size in Megabytes. Example:- $du o/p :- ? $du /home/bmi/text Output:- 12 /home/bmi/text $du –a /home/bmi/text Output:- 4 /home/bmi/text/x.txt 4 /home/bmi/text/y.txt 12 /home/bmi/text 04/23/11 UNIT-I : UNIX Introduction
  • 28. 7.df (Disk Free) This df command reports the available free space on the mounted file system or disks. Syntax:- df [-option] Options Description -l Shows local file system only -k Displays the size in kilobytes -m Displays the size in Megabytes -i Reports free used percentage of used inode. This command reports the free space in blocks. Generally one block in 512 bytes. The i-nodes entry indicates that up to the specified number of files can be created on the file. Example:- $df 04/23/11 UNIT-I : UNIX Introduction File System 1-Blocks Used Available Used Mounted On /dev/hda8 1612808 63632 1467248 5% / /dev/hda8 23302 3489 18610 16% /boot /dev/hda9 1035660 7100 975952 1% /home /dev/hda10 1778840 742916 945560 44% /usr /dev/hda11 1517920 1517920 1423784 2% /var
  • 29. 1.cat :- Means Concatenate i.e. To add more than one string. 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 . cat command provides the various facility in UNIX Operating System. This various facility is also called various flavors of cat command. 04/23/11 UNIT-I : UNIX Introduction
  • 30. 04/23/11 UNIT-I : UNIX Introduction
  • 31. 04/23/11 UNIT-I : UNIX Introduction
  • 32. 04/23/11 UNIT-I : UNIX Introduction
  • 33. 04/23/11 UNIT-I : UNIX Introduction
  • 34. 04/23/11 UNIT-I : UNIX Introduction
  • 35. 04/23/11 UNIT-I : UNIX Introduction
  • 36. 04/23/11 UNIT-I : UNIX Introduction
  • 37. 2.cp [Copy]:- This command is used to copy the content of one file into another. If the destination is an existing file , the file is overwritten . If the destination is an existing directory the file is copied into that directory. Syntax:- cp [-option] <source_file> < destination_file> where options can be:- i – prompt before overwritten destination files. p - Preserve all information ,including owner , group , permission and timestamps. R - Recursively copies files in all subdirectories. Example:- $cp myfile myfile1 Output:- $cat myfile I am file one. $cat myfile1 I am file one. 04/23/11 UNIT-I : UNIX Introduction
  • 38. 3. rm [Remove]:- 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. Syntax:- rm [-option] <filename> where options are as follows:- r - deletes all directories including the lower order directories. Recursively deletes entire contents of the specified directory and the directory itself . i - Prompts before deleting f - Removes write – protected files also, without prompting. Example:- $rm myfile1 This command deletes the file myfile form the current directory. $rm –f /usr/ibrahim This command deletes all the files and subdirectories of the specified directory /usr/ibrahim. Note that the directory ‘ibrahim’ also will be delted. 04/23/11 UNIT-I : UNIX Introduction
  • 39. 4.mv [Move] This command is used to remove the specified files / directories. Syntax:- $mv <source> <destination> Example:- mv file1.txt file2.txt Output:- $cat file1.txt File Not Found $cat file2.txt I am file1. 04/23/11 UNIT-I : UNIX Introduction
  • 40. 5. wc [Word Count] This command is used to display the number of lines,words and characters of information stored on the specified file. Syntax:- wc [-option] <File_Name> Where l - Displays the number of lines in the file w – Displays the number of words in the file c – Display the number of characters in the file Examples:- Command Output $cat file1 I am file1 $wc file1 1 3 10 file1 $wc –l file1 1 file1 $wc –w file1 3 file1 $wc –c file1 10 file1 04/23/11 UNIT-I : UNIX Introduction
  • 41. 6.ln(Link) 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. Syntax:- ln <filename> <additional_filename> 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. Example:- $ls –l test1.txt -rw-rw-r-- 1 bmi bmi 75 jan 13 14:35 test1.txt $ln test1.txt test2.txt $ls –l test*.txt -rw-rw-r-- 2 bmi bmi 75 jan 13 14:35 test1.txt -rw-rw-r-- 2 bmi bmi 75 jan 13 14:35 test2.txt $rm test1.txt $ls –l test2.txt -rw-rw-r-- 1 bmi bmi 75 jan 13 14:35 test2.txt 04/23/11 UNIT-I : UNIX Introduction
  • 42. 7.file This command lists the general classification of a specified file. It lets you to know if the contents of the specified file is ASCII text , C program text , directory and others. Syntax:- file <filename> Example:- $file test1.txt Output test1.txt : ASCII text. $file * Output test1.test: ASCII text xyz: Directory 04/23/11 UNIT-I : UNIX Introduction
  • 43. 8.cmp [Compare] This command is used compare two files. Syntax:- cmp <filename1> <filename2> This command reports the first instance of differences between the specified files. That is the two files are compared byte by byte and the location of the first mismatch is echoed to the screen. Example:- $cat file1.txt I am Ram What is your name? $cat file2.txt I am Ram What are you doing? $cmp file1.txt file2.txt Output file1.txt file2.txt differ : byte 10 char 1, line2 04/23/11 UNIT-I : UNIX Introduction
  • 44. 9. comm [Common] This command uses two sorted files as argumnets and reports what is common.It compares each line of the first with its corresponding line in the second file. The output of this command is in three column as follows: Column1 : Contains lines common for both filename 1 and filename2 Column2 : Contains lines unique to filename2. Column3 : Contains lines unique to filename1. Syntax:- comm [-option] <filename1> <filename2> Option:- 1 - Suppresses listing of column1 2 - Suppresses listing of column2 3 - Suppresses listing Example:- $cat file1.txt $cat file2.txt I am Ram I am Ram What is your name? What are you doing? $comm file1.txt file2.txt Output:- I am Ram What are you doing? What is your name? 04/23/11 UNIT-I : UNIX Introduction
  • 45. 10. nl [ Non-Blank Line] This command numbers all non-blank line in the specified text file and display the same on the screen. Syntax:- nl <filename> Example:- $cat file1.txt I am Ram What is your name? $nl file1.txt Output:- 1 I am Ram 2 What is your name? 04/23/11 UNIT-I : UNIX Introduction
  • 46. 11. tac This command reverses a file contents , so that the last line becomes the first line. Syntax:- tac <filename> Example:- $cat file1.txt I am Ram What is your name? $tac file1.txt Output:- What is your name? I am Ram 04/23/11 UNIT-I : UNIX Introduction
  • 47. 12. tail This command displays the end of the specified file. Syntax:- tail -n <filename> Example:- $cat student.txt Mohan always keeps himself to himself. We were in a hurry. The road being zigzag , We had to cut off a corner to reach in time. In his youth , he was practically rolling in money. $tail -1 file1.txt Output:- In his youth , he was practically rolling in money. $tail -2 file1.txt Output:- We had to cut off a corner to reach in time. In his youth , he was practically rolling in money. 04/23/11 UNIT-I : UNIX Introduction
  • 48. 12. head This command displays the top of the specified file. Syntax:- head -n <filename> Example:- $cat student.txt Mohan always keeps himself to himself. We were in a hurry. The road being zigzag , We had to cut off a corner to reach in time. In his youth , he was practically rolling in money. $head -1 file1.txt Output:- Mohan always keeps himself to himself. $tail -2 file1.txt Output:- Mohan always keeps himself to himself. We were in a hurry. The road being zigzag , 04/23/11 UNIT-I : UNIX Introduction
  • 49. UNIX treats everything as files.There are 3 types of files in UNIX as follows:- 1.Ordinary File 2.Directory File 3.Special File There are 3 types of modes for accessing these files as follows:- 1. Read Mode(r) 2.Write Mode(w) 3.Execute Mode(x) Unix separates its users into 3 groups for securty and convenience as follows :- 1. user (u) 2. user group(g) 3. others(o) 04/23/11 UNIT-I : UNIX Introduction
  • 50. 13. chmod [ Change Mode] This command is used to change the file permissions for an existing file. We can use any one of the symbolic and octal notations to change file permissions. Syntax:- chmod <user_symbols set/deny_symbol access_symbol > <filename> 14 chgrp[Change Group] This command is used to change the group ownership of specified file. Syntax:- chgrp <new_group name> <filename> 15.chown [Change Owner] This command is used to change the owner of a specified file. Syntax:- chown <new_owner> <filename> 04/23/11 UNIT-I : UNIX Introduction
  • 51. 04/23/11 UNIT-I : UNIX Introduction
  • 52. 04/23/11 UNIT-I : UNIX Introduction 1.date :- This command displays the current system date. Syntax:- date + <format> %H Hour 00 to 23 %I Hour 00 to 12 %M Minute 00 to 59 %S Second 00 to 59 %D Date MM/DD/YY %T Time HH:MM:SS %w (SMALL) Day of the Week %r Time in AM & PM %y Last two digits of the year
  • 53. 04/23/11 UNIT-I : UNIX Introduction Command Output $date MON JAN 07 15:10:10 IST 2008 $date +%H 15 $date +%I 03 $date +%M 10 $date +%w 2 (0-Sunday , 1-Monday , 2-Tuesday , 3-Wednesday , 4-Thursday , 5-Friday, 6-Saturday) $date +%r 03:10:10 PM
  • 54. 2. Who 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. Syntax & Example :- $who Output:- Aman tty1 jan 07 10:17 Shwetabh tty2 jan 07 10:20 Neha tty4 jan 07 10:30 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. 04/23/11 UNIT-I : UNIX Introduction
  • 55. 3. Who am I This commands tells you who you are. (Working on the current terminal). Syntax & Example :- $who am i Output:- Aman tty1 jan 07 10:17 04/23/11 UNIT-I : UNIX Introduction
  • 56. 4.man (Manual) This command displays the syntax and detailed usage of the UNIX command , which is supplied as argument. Syntax :- $man <UNIX_COMMAND> Example:- $man wc This will display the help details for “wc” command. Almost all of the command offer – help option that displays a short listing of all the options. $wc --help 04/23/11 UNIT-I : UNIX Introduction
  • 57. 5. cal (calculator) This command will display the calender for the specified month and year. Syntax :- $cal [month] <year] where month can be ranged form 1 to 12 Example:- $cal 2008 This command will display calender for thr year 2008 (from 1 to 12 months). $cal 1 2008 This command will display the calender for the month january of the year 2008. 04/23/11 UNIT-I : UNIX Introduction
  • 58. 6. lpr (Line Printer) This command is used to print one or more files on printer. Syntax :- $lpr [-option] <filename1>………………..<filenamen> where options can be :- r – Removes file(s) form directory after printing. m – Mail inform you when printing is over. Example:- $lpr file1.txt 04/23/11 UNIT-I : UNIX Introduction
  • 59. 7. expr This command is used to perform arithmetic operations on integer. The arithmetic operator and their corresponding functions are given below. Syntax :- + Addition - Subtraction \* Multiplication / Division [It gives my quotient of the division] % Remainder of division [ Modulas operator ] 04/23/11 UNIT-I : UNIX Introduction
  • 60. 8. bc [Basic Calculator] This command is used to perform arithmetic operation on integer as well as on floats (Decimal Number]. 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. Example :- Add 10 and 20 $bc 10 + 20 30 ^d 04/23/11 UNIT-I : UNIX Introduction
  • 61. $bc 10 / 3 3 [Decimal portion is truncated] ^d $bc scale = 1 8 / 3 2.6 scale = 2 8 / 3 2.66 ^d 04/23/11 UNIT-I : UNIX Introduction
  • 62. $bc 1. ibase = 2 ----set ibase to binary (2). 101 -----Type the input binary number. 5 -----Result in Decimal obase = 2 ----set obase to binary(2). 5 ----Type the input decimal number 101 ----Result in Binary form ^d Here similarly for Octal and hexadecimal numbers. 04/23/11 UNIT-I : UNIX Introduction
  • 63. 04/23/11 UNIT-I : UNIX Introduction
  • 64. PIPE :- Pipe is a mechanism in which the output of one command can be redirected as input to another command. Syntax:- command | command2 The output of command1 is sent to command2 as input. Example:- $ls | more 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 . $cat file1.txt | sort file1.txt |wc file1.txt 04/23/11 UNIT-I : UNIX Introduction
  • 65. REDIRECTION :- 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”. 1.Redirecting inputs 2.Redirecting outputs 3.Redirecting Error messages 1.Redirecting inputs :- The ‘<‘ symbol is used to redirect inputs. Example:- $cat < file1.txt then the file1.txt is taken as input for the command – cat 2.Redirecting outputs:- The “>” symbol is used to redirect outputs. Example:- $ls > list.doc Then the output of the command ‘ls’ is stored on the file “list.doc”. We can also use ‘ 1>’ instead of ‘>’. 3.Redirecting Error Messages:- The ‘2>’ symbol is used to redirect error messages. Example :- $cat list1.doc 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. Example:- $cat list1.doc 2> error.txt Then the error messages , if generated , will be stored on the disk – error.txt. 04/23/11 UNIT-I : UNIX Introduction
  • 66. FILTERS:- 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. sort :- This command sorts the contents of a given file based on ASCII values of characters. Syntax:- sort [-option] <filename> Options -m <filelist> =Merge sorted files specified in <filelist> -o <filename> =stores output in the specified <filename> -r = Sorts the contents in reverse order. -u = Removes duplicate lines and display sorted content. -c= Checks if the file is sorted or not. Example:-$cat file.txt $sort file.txt E A S E A S W W 04/23/11 UNIT-I : UNIX Introduction
  • 67. 2. grep [Global Regular Expression Printing] :- This command is used to search for a specified pattern form a specified file and display those lines containing the patter. Syntax:- grep [-option] pattern <filename> Where options -b ignores spaces , tab. -i Ignore case -v Displays only the lines that do not match the specified pattern. -e Displays the total number of occurrences of the pattern in the file. -n Displays the resultant lines along with their line number. Example:- $cat emp.ext 1001 Ram Computer CS 1002 Merry Electronics ET 1003 John Computer CS 04/23/11 UNIT-I : UNIX Introduction
  • 68. $grep “CS” emp.txt o/p:- 1001 Ram Computer CS 1003 John Computer CS Regular Expression Character Set *: Represents any number of characters ?: Represents any single character. [r1-r2]: Range [^abcd] : Matches a single character which is not a,b,c or d. ^[character]: Matches the lines that are beginning with the character specified in <Character> [character]$ :Matches the lines that are ending with the character specified in <character> Example:- $grep “Com*” emp.txt o/p:- 1001 Ram Computer CS 1003 John Computer CS 04/23/11 UNIT-I : UNIX Introduction
  • 69. Related commands with grep:- 1.egrep [ Extended grep] 2.fgrep [ Fixed grep] egrep :- This command offers additional features than grep. Multiple patterns can be searched by using pipe symbol. 04/23/11 UNIT-I : UNIX Introduction
  • 70. 3.uniq {Unique} 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. Syntax:- uniq [-option] <filename> Where options are as follows:- -u ==Displays only the no –repeated lines. -d ==Displays only the duplicate lines. -c ==Displays each line by eliminating duplicate lines and prefixing the number of times it occurs. Example:- $cat abc.txt abc xyz abc pqr $uniq abc.txt abc xyz abc pqr 04/23/11 UNIT-I : UNIX Introduction
  • 71. $uniq –u abc.txt O/P:- xyz pqr $uniq –d abc.txt O/P:- abc $uniq –c abc.txt O/P:- 2 abc 1 xyz 1 pqr 04/23/11 UNIT-I : UNIX Introduction
  • 72. cut :- This command is used to cut the columns/ fields of a specified file [Like the head and tail commands cut the line-rows]. Syntax:- cut [-option] <filename> Where options c <Columns> -Cuts the column specified in <columns>. You must separate the column numbers by using commas. f <Fields> - Cuts the fields specified in <fields> . You must separate field number by using commas. Example:- $cat emp.txt 1001 John Computer Cs 1002 Merry Electronics ET 1003 Ram Computer CS 04/23/11 UNIT-I : UNIX Introduction
  • 73. $cut –c 2-5, 11-15 emp.txt Output:- 001 Compu 002 Elec 003 Comp $cut -f 2,3 emp.txt Output:- John Computer Merry Electronics Ram Computer $cut –d “|” –f 1,3- emp.txt 1001 Computer CS 1002 Electronics ET 1003 Computer CS $cut –f 1-3 emp.txt Output:- 1001 John Computer 1002 Merry Electronics 1003 Ram Computer 04/23/11 UNIT-I : UNIX Introduction
  • 74. paste:- This command concatenate the contents of the specified files into to a single file vertically. [Cut command separates the columns , this paste command merges the columns]. Syntax:- paste <Filename1> <filename2>………<filename n> Example:- $cat e1.txt $cat e2.txt 1001 1004 1002 1005 1003 1006 $paste e1.txt e2.txt Output:- 1001 1002 1003 1004 1005 1006 04/23/11 UNIT-I : UNIX Introduction
  • 75. tr [Translating Character] This tr command filter manipulates individual characters in a line. More specifically , it translates characters using one or two compact expressions: tr options expression1 expression2 standard input tr takes input only from the standard input , it doesn’t take a filename as argument. By default it translates each character in expression1 to its mapped counterpart in expression2. The first character in the first expression is replaced with the first character in the second expression and similarly for the other characters. 1. Replace a character:- $cat emp.txt Output:- 1001 | John | Computer | CS 1002 | Merry | Electronics | ET 1003 | Ram | Computer | CS 04/23/11 UNIT-I : UNIX Introduction
  • 76. $tr ‘|’ ‘-’ emp.txt Output:- 1001 - John - Computer - CS 1002 - Merry - Electronics - ET 1003 - Ram - Computer - CS 2. Changing Case a Text $cat emp.txt | tr ‘[a-z]’ ‘[A-Z]’ Output:- 1001 | JOHN | COMPUTER | CS 1002 | MERRY |ELECTRONICS | ET 1003 | RAM | COMPUTER |CS $cat emp.txt | tr ‘C,p’ ‘c,P’ Output:- 1001 | John | comPuter | cS 1002 | Merry | Electronics | ET 1003 | Ram | comPuter | CS 04/23/11 UNIT-I : UNIX Introduction
  • 77. 3. Deleting Characters (-d):- $cat emp.txt Output:- 1001| John | Computer | CS 1002| Merry | Electronics | ET 1003| Ram | Computer | CS $tr –d ‘|’ emp.txt Output:- 1001 John Computer CS 1002 Merry Electronics ET 1003 Ram Computer CS 04/23/11 UNIT-I : UNIX Introduction
  • 78. sed [Stream Editor]:- This is a multipurpose tool which combines the work of several filters. It is derived from ed , the original editor. sed performs non-interactive operations on a data stream – hence its name . sed uses instructions to act on text. An instruction combines an address for selecting lines , with an action to be taken on them as shown by the syntax:- sed [options]/[Edit Commands] ‘address action’ files The address and action are enclosed within single quotes. Addressing in sed is done in two ways:- By one or two line numbers. By specifying a /- enclosed pattern which occurs in a line. Where edit commands can be:- i – Inserts after line a – Appends after line c – Changes lines d – Deletes lines p – Prints lines q – Quits 04/23/11 UNIT-I : UNIX Introduction
  • 79. Example1:-$sed ‘2q’ emp.txt Output:- 1001 John Computer CS 1002 Merry Electronics ET This command displays the 1 st two lines of the emp.txt file. Example2:- $sed ‘2d’ emp.txt Output:- 1001 John Computer CS 1003 Ram Computer CS This command displays the contents of emp.txt by deleting the second line. Example3:- $sed –n ‘2p’ emp.txt Output:- 1002 Merry Electronics ET This command displays the second line of the emp.txt. Example4:- $sed –n ‘2,4p’ emp.txt This command displays the lines 2 through 4 of emp.txt. Example5:- $sed –n ‘$p’ e mp.txt This command displays the last line of emp.txt. 04/23/11 UNIT-I : UNIX Introduction
  • 80. Example6:- $sed -1 ‘/cs/p’ emp.txt This command displays the lines that are containing the pattern “cs”. Example7: - $sed ‘/cs/d’ emp.txt This command displays the lines that are not containing the specified pattern “ cs”. Example8:- $sed ‘i\ ---------------------------------’ emp.txt This command inserts the specified dash line before each line of the file emp.txt. Example9:- $sed ‘a\ --------------------------------’ emp.txt This command inserts the specified dash line after each line of the file emp.txt. Example10:- $sed ‘3i\ ------------------------------- ‘ emp.txt This command inserts the specified dash line before the third line of the file emp.txt. Example10:- $sed ‘3a\ ------------------------------- ‘ emp.txt This command inserts the specified dash line after the third line of the file emp.txt. Example 11:- $sed ‘$a\ -----------------------------------’ emp.txt This command inserts the specified dash line after the last line of the file emp.txt 04/23/11 UNIT-I : UNIX Introduction
  • 81. 04/23/11 UNIT-I : UNIX Introduction yacc - yet another compiler-compiler The yacc command converts a context-free grammar into a set of tables .The lex command is useful for creating lexical analyzers usable by yacc.
  • 82. 04/23/11 UNIT-I : UNIX Introduction
  • 83. 04/23/11 UNIT-I : UNIX Introduction 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. vi [<filename>] A status line at the bottom of the screen (25th line) shows the filenames, current line and character position in the edited file. vi + <line_number> <filename> Edits the file specified in <filename> and places the cursor on the <line_number>th line.
  • 84. 04/23/11 UNIT-I : UNIX Introduction aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccccccccccc ddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeee ~ ~ ~ ~ ~ ~ ~ :wq
  • 85. 04/23/11 UNIT-I : UNIX Introduction vi Modes Insert/Input Mode Command Mode Ex-Mode
  • 86.  
  • 87.  
  • 88.  
  • 89.  
  • 90.  
  • 91.  
  • 92.  
  • 93.  
  • 94.  
  • 95.  
  • 96.  
  • 97.  
  • 98. 04/23/11 UNIT-I : UNIX Introduction Input Mode Ex-Mode Command Mode Shell vi foo :x, :q :wq & ZZ [Enter] : [Esc] i,I,a,A,o,O,r,R,s, and S T H E T H R E E M O D E S
  • 99. 04/23/11 UNIT-I : UNIX Introduction Insert Mode :- 1) The text should be entered in this mode and any key press in this mode is treated as text. 2) We can enter into this mode from command mode by pressing any of the keys: i I a A o O r R s S
  • 100. 04/23/11 UNIT-I : UNIX Introduction Command Mode:- It is the default mode when we start up vi-editor. All the commands on vi-editor (Cursor movement text manipulation etc. ) should be used in this mode. We can enter into this mode from insert mode by pressing the [Esc] key and from Ex Mode by pressing [Enter Key]. Ex Command Mode:- 1. The Ex command mode (Saving files , find , replace etc ..) can be entered at the last line of the screen in this mode. 2)We can enter into this mode from command mode by pressing [:] key.
  • 101. 04/23/11 UNIT-I : UNIX Introduction Insert Commands i Inserts before cursor. I Inserts at the beginning of the current line. a Appends at the end of the current line. A Appends at the start of the current line. o Inserts a blank line below the current line. O Inserts a blank line above the current line.
  • 102. 04/23/11 UNIT-I : UNIX Introduction Delete Commands x -Deletes a character at the cursor position. <n>x-Deletes specified number (n) of character. X -Deletes a character before the cursor position. <n>X -Deletes specified number (n) of characters before the cursor position. dw -Deletes from current position to end of the current word. db -Deletes from cursor position to beginning of current word. dd -Deletes current line. <n>dd -Deletes specified number of lines (n) from the current line.
  • 103. 04/23/11 UNIT-I : UNIX Introduction Replace Commands r – Replaces single character at the cursor position. R –Replaces characters until[ESC] key is pressed from current cursor position. s – Replaces single character at the cursor position with any number of character. S – Replaces entire line. Search Commands /string [Enter] – Searches the specified string forward in the file. ?string [Enter]- Searches the specified string backward in the file. n - Finds the next string in the same direction. N - Finds the next string in the opposite direction.
  • 104. 04/23/11 UNIT-I : UNIX Introduction Yanking (Copy & Paste) Commands yy or (y) : Yanks the current line into the buffer (Copy). nyy or ny : Copies the ‘n’ lines from the current line to the buffer. p : Paste the yanked text below the current line. P : Paste the yanked text above the current line. Ex Mode Commands :w – Saves file without quitting :w <filename> - Saves the content into a file specified in <filename> :x or :wq – Saves file and quits from vi. :q! – Quits from vi without saving.
  • 105. 04/23/11 UNIT-I : UNIX Introduction SET Commands The two set command i.e. set nu and set ic. The first is used to associate line numbers with the file . You are currently working with . The second is used to ignore the case while searching a pattern in the file. In addition to those two there are several other options that the user can set to customize the environment of vi. To get a list of all the options available with set , use the command: (ESC): set all Thought the list is long there are only a few which are most commonly used .
  • 106. 04/23/11 UNIT-I : UNIX Introduction A list of these along with the affect of each is shown in figure:- :set nu Set display of line numbers on. :set nonu Set display of line numbers off (Default). :set eb Beep the speaker when an error occurs (Default). :set noeb Do not Beep the speaker when an error occurs. :set ai Set auto indent on. :set noai Set auto indent off (default). :set ic Ignores case while searching a pattern. :set noic Do not Ignores case while searching a pattern (default).
  • 107. 04/23/11 UNIT-I : UNIX Introduction .exrc Profile and Miscellaneous Commands Type :To Ctrl-g s how line number of current line. Ctrl-l redraw the entire display . :!sh fork a shell. :type Ctrl-d to get back to vi. . repeat last text change command at current cursor position. :set showmode s how when you are in insert mode . :set ic ignore case when searching. :set noic turn ignore case off. :set nu turn on line numbering. :set nonu turn line numbering off. NOTE:- 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.