Rishav Mishra final presentation on UNIX Final.pptx

rishavmishra041 17 views 206 slides Sep 12, 2024
Slide 1
Slide 1 of 206
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
85
Slide 86
86
Slide 87
87
Slide 88
88
Slide 89
89
Slide 90
90
Slide 91
91
Slide 92
92
Slide 93
93
Slide 94
94
Slide 95
95
Slide 96
96
Slide 97
97
Slide 98
98
Slide 99
99
Slide 100
100
Slide 101
101
Slide 102
102
Slide 103
103
Slide 104
104
Slide 105
105
Slide 106
106
Slide 107
107
Slide 108
108
Slide 109
109
Slide 110
110
Slide 111
111
Slide 112
112
Slide 113
113
Slide 114
114
Slide 115
115
Slide 116
116
Slide 117
117
Slide 118
118
Slide 119
119
Slide 120
120
Slide 121
121
Slide 122
122
Slide 123
123
Slide 124
124
Slide 125
125
Slide 126
126
Slide 127
127
Slide 128
128
Slide 129
129
Slide 130
130
Slide 131
131
Slide 132
132
Slide 133
133
Slide 134
134
Slide 135
135
Slide 136
136
Slide 137
137
Slide 138
138
Slide 139
139
Slide 140
140
Slide 141
141
Slide 142
142
Slide 143
143
Slide 144
144
Slide 145
145
Slide 146
146
Slide 147
147
Slide 148
148
Slide 149
149
Slide 150
150
Slide 151
151
Slide 152
152
Slide 153
153
Slide 154
154
Slide 155
155
Slide 156
156
Slide 157
157
Slide 158
158
Slide 159
159
Slide 160
160
Slide 161
161
Slide 162
162
Slide 163
163
Slide 164
164
Slide 165
165
Slide 166
166
Slide 167
167
Slide 168
168
Slide 169
169
Slide 170
170
Slide 171
171
Slide 172
172
Slide 173
173
Slide 174
174
Slide 175
175
Slide 176
176
Slide 177
177
Slide 178
178
Slide 179
179
Slide 180
180
Slide 181
181
Slide 182
182
Slide 183
183
Slide 184
184
Slide 185
185
Slide 186
186
Slide 187
187
Slide 188
188
Slide 189
189
Slide 190
190
Slide 191
191
Slide 192
192
Slide 193
193
Slide 194
194
Slide 195
195
Slide 196
196
Slide 197
197
Slide 198
198
Slide 199
199
Slide 200
200
Slide 201
201
Slide 202
202
Slide 203
203
Slide 204
204
Slide 205
205
Slide 206
206

About This Presentation

PPT is based on Unix


Slide Content

Mos using Unix/ linux

Session - 1 Objectives Introduction about OS Introduction to Unix/Linux Versions of Unix/Linux Structure of Linux Kernel and Shell File and Directory structure

What is Linux Linux is a UNIX clone It can run on 32 bit and 64 bit hardware Linux is a true multitasking environment Fully capable of taking advantage of multiple processors Can address up to 64 GB of RAM Partial POSIX Compliance POSIX  , an acronym for "Portable Operating System Interface ",  is a family of standards specified by the IEEE for maintaining compatibility between operating systems. POSIX defines the application programming interface (API), along with command line shells and utility interfaces, for software compatibility with variants of Unix and other operating systems

Linux – Free Software Free software, as defined by the FSF (Free Software Foundation), is a "matter of liberty, not price." To qualify as free software by FSF standards, you must be able to: Run the program for any purpose you want to, rather than be restricted in what you can use it for. View the program's source code. Study the program's source code and modify it if you need to. Share the program with others. Improve the program and release those improvements so that others can use them.

History The history of Linux began with Unix in 1969 Unix was created at Bell Labs with the goals: Simplicity Recyclable code Written in C as opposed to assembly Development started in 1991 Linus Torvalds wanted to create a free implementation of UNIX By 1993 there were 12000 Linux users Today Linux rivals UNIX in stability and scalability

OS and its Function

Linux Structure

Linux structure Linux components are divided into 3 parts. Kernel Environment File Structure

Kernel It is a core program that executes all other programs First loaded in computer Handles the hardware devices. Like CPU Memory I/O Devices

Environment Provides interface to user Receives commands from user and send to kernel for execution Called as interpreter Types of Environment Desktop Window managers Command line (shell)

Way of storing files The Unix file system looks like an tree structure. File structure starts with a Root Directory (/). File structure doc home bin usr var dev etc sbin / (root) bin sbin lib share man

File structure Directory Function / Begins the file structure /home Contains user’s home directory /bin Holds the standard commands /usr Holds the commands used by the system /usr/bin Holds user oriented commands /usr/sbin Holds system administration commands /usr/lib Holds the library program files

File structure Directory Function /usr/share/doc Holds the Linux documentation /usr/share/man Holds the online man files /var/spool Holds the spool files, such as those generated for printing jobs and network transfer /sbin Holds the system administration commands for booting the system /var Holds the files that vary, such as mailbox files /dev Holds file interfaces for devices such as the terminal and printers /etc Holds the system configuration files

SHELL

Shell The shell is a command interpreter that provides an interface between user and the operating system. Shells used in Linux Bash Shell (Bourne Again Shell) Korn Shell (Ksh) C Shell (Csh)

Linux Command Line The Linux shell displays a prompt Prompt should be one single character or multiple line Shells prompt are handled by PS1 & PS2

Shell prompts Bash Shell ( default shell) - - $ C Shell - - % Korn Shell - - $ Root - - #

Session - 2 Objective Unix File System Indirection Technique

Unix File System

Boot Block It is located in the first few sectors of a file system. The boot block contains the initial bootstrap program used to load the operating system.  Only one File System Contains a Boot Program, other File System contains an empty boot block.

Super Block Each filesystem has one super block, it contains info about Type of filesystem (ext2, ext3...) The block size Pointers to a list of free blocks The inode number of the root directory Contains the layout of the Disk – Size of Disk – Number of Inodes – Number of Data Blocks – Where inodes start, where data blocks start, etc….

Inode Table Every file have one inode and vice versa. In linux every file is recognized with integer number known as inode number. This structure consists of info of file about Which disk blocks go with which file. Data structure for bookkeeping – List of Blocks – File or Directory – Link Count – Other information…owner/permissions

Inode Table in Details file ownership indication file type (e.g., regular, directory, special device, pipes, etc.) file access permissions. time of last access, and modification number of links (aliases) to the file pointers to the data blocks for the file  size of the file in bytes (for regular files), major and minor device numbers for special devices. Inodes include pointers to the data blocks. Each inode contains 15 pointers: the first 12 pointers point directly to data blocks the 13th pointer points to an indirect block, a block containing pointers to data blocks the 14th pointer points to a doubly-indirect block, a block containing 128 addresses of singly indirect blocks the 15th pointer points to a triply indirect block (which contains pointers to doubly indirect blocks, etc.)

Data Block This is where the file data itself is stored. Since a directory is simply a specially formatted file, directories are also contained in the data blocks. An allocated data block can belong to one and only one file in the system. If a data block is not allocated to a file, it is free and available for the system to allocate when needed.

Directories Like a file: List of files and directories – name – inode number Can read it like a file Always has at least 2 entries: “.” current directory “..” parent directory

Session - 3 Linux Commands

Linux Commands

Command name - - clear Purpose - - Clear the user screen Syntax - - clear Ex - - $ clear General commands

Command name - - exit or logout Purpose - - Quit Linux Syntax - - exit Ex - - $ exit Ctrl - d General commands

Command name - - uname Purpose - - Display the kernel name Syntax - - uname Ex - - $ uname Output $uname Linux $ General commands

Command name - - date Purpose - - Display the current system date and time. Syntax - - date Ex - - $ date Output $date Sat jul 02 10:10:50 BDT 2011 $ General commands

Command name - - who Purpose - - Display the information of all active login user. Syntax - - who Ex - - $ who Output $who root tty1 jul 2 10:20 user1 tty2 jul 2 11:08 user5 tty3 jul 2 12:05 $ General commands

Command name - - who am i Purpose - - Display the information of the user. Syntax - - who am i Ex - - $ who am i Output $who am i user1 tty2 jul 2 11:08 $ General commands

Command name - - tty Purpose - - Display the file name of terminal connected to standard input Syntax - - tty Ex - - $ tty Output $ tty General commands

Command name - - cal Purpose - - Display the cal of a specified date. Syntax - - cal [month][year] Ex - - $ cal Display the calendar of the current month. $cal 07 2011 Display the calendar of the July 2011 $cal 2011 Display the calendar of the 2011 General commands

Escape sequence characters \n - new line character \c – continue character Ex- printf “ rkcit \n ” rkcit $ General commands

Command name - - echo Purpose - - Same as printf . Syntax - - echo “MESSAGE” Ex - - $ echo “ rkcit ” Ourput - - $ echo “ rkcit ” rkcit $ General commands

Session - 04 Objectives Directory Management Commands Wildcards File management Commands Redirection Aim - - To provide knowledge about Directory & File management in Linux

Every directory and file are listed in its parent directory. In the case of the root directory, that parent is itself. A directory is a file that contains a table listing the files contained within it, giving file names to the inode numbers in the list. The information about all the files and directories is maintained in INODE TABLE An Inode (Index Nodes) is an entry in the table containing information about a file including file permissions, UID, GID, size, time stamp, pointers to files data blocks on the disk etc.

Directory Management Commands

Directory Management Commands Command name - - pwd Purpose - - Display the complete path of the current working directory. Syntax - - pwd Ex - - $ pwd Ourput - - $ pwd /home/user1 $

Command name - - ls Purpose - - Lists files & subdirectory names under certain directory. Syntax - - ls [option] [directory_name] Ex - - $ ls Ourput - - $ ls weather reports letters $ ls /home/user2/king Sunday Monday Tuesday Directory Management Commands

Options of ls Command Option Purpose -x Get multi-columnar output. -r List files & sub-directories in reverse order. -t List files & sub-directories in time order. -a List all files including hidden files. -A List all files excluding . And .. -c All files by inode modification time. -i List the inode for each file. -l Display permissions, owner, size, modification time etc. Directory Management Commands

Ex - - $ ls - l total 20 drwxrwxr-- 2 user1 grp1 4096 Nov 29 01:51 Orissa drwxrwxr-X 3 user2 grp2 4096 Nov 29 01:54 Cool -rwxrw - - - - 1 user3 grp1 18 Nov 30 04:38 report drwxrwxr-X 2 user1 grp1 4096 Dec 09 10:50 south -rw –r- - - - 1 user1 grp1 23 Nov 29 01:54 king Type Permissions Links owner group Size in bytes Modification Date & Time File name Directory Management Commands

Wildcards

Wildcards . . . Special symbols can be used along with different commands. Wildcard Used to * Match any number of character including zero. ? Match one and only character [abc] Match one character which should be either a, b or c. [!abc] Match one character which is not a, b or c. [p-t] Match one character which falls within the range of p-t [!p-t] Match one character which does not falls within the range of p-t

Examples $ ls p* (Display all names of files & directories starts with p) $ ls ?? (Display all names of files & directories having any two characters) $ ls linux[1234] linux1 linux2 linux3 linux4 Wildcards

$ ls linux[!12] linux4 linux5 linux8 $ ls uni[x-z] unix uniy uniz (Display all files & directories starts with uni and followed by x, y & z.) $ ls Linux[!0-9] (Display all files & directories starts with Linux and followed by a non-numeric characters) Wildcards

Command name - - mkdir Purpose - - Creates a new directory. Syntax - - mkdir [path]<Directory Name> Directory Management Commands

Ex- $ pwd /home/user1 $ mkdir india home root (/) cool sunday user1 $ ls india $ mkdir /home/user1/cool/orissa india orissa Directory Management Commands

Command name - - cd Purpose - - Change the current directory. Syntax - - cd [path][Directory Name] Directory Management Commands

Ex- $ pwd /home/user1 $ ls india Sunday cool home root (/) cool sunday user1 india $ cd india $ pwd /home/user1/india $ Directory Management Commands

$pwd /home/user1/india home root (/) cool sunday user1 india $ cd /home/user1/cool $ pwd /home/user1/cool $ cd $pwd /home/user1 Directory Management Commands

Session - 05 Objectives Directory Management Commands File management Commands Redirection Aim - - To provide knowledge about Directory & File management in Linux

Command name - - rmdir Purpose - - Delete a directory if it is empty. Syntax - - rmdir [path]<Directory Name> Directory Management Commands

Ex- $ ls india cool sunday home root (/) cool sunday user1 india $ rmdir india $ ls cool sunday Directory Management Commands

File Management Commands

File Management Commands Command name - - cat Purpose - - Used to create & to display the content of a file. Syntax - - cat <filename>

Ex- - $cat > myfile1 write the contents of file. (ctrl-d) $ $cat myfile1 contents of myfile1. $ File Management Commands

Command name - - cp Purpose - - Creates copy of a file. Syntax - - cp <source-file> <destination-file> File Management Commands

$ cp /home/user1/india/file1 /home/user1/Sunday/file1 File1 (F) india home root (/) cool sunday user1 File1 (F) File Management Commands

Command name - - mv Purpose - - Move a file from one directory to another. Rename a file. Syntax - - mv <source-file> <destination-file> File Management Commands

$ mv /home/user1/india/file1 /home/user1/Sunday/file1 File1 (F) india home root (/) cool sunday user1 File Management Commands

$ mv /home/user1/india/file1 /home/user1/india/file2 File1 (F) india home root (/) cool sunday user1 File2 (F) File Management Commands

Command name - - rm Purpose - - Delete a file. Syntax - - rm <filename> home root (/) cool sunday user1 File1 (F) Ex- $ pwd /home/usr1 $ rm file1 File Management Commands

Different views of a file. Page wise - - pg, more Top of a file - - head Bottom of a file - - tail File Management Commands

Page wise - - pg To display the contents of a file or a command at one time. $ pg linux01.txt Enter – new line File Management Commands

Page wise - - more To display the contents of a file or a command at one time. $ more linux01.txt Space bar – next page Enter – next line File Management Commands

head - - To display the top of a file. $ head (by default it will display top 10 lines) $ head -6 my_file (it will display only top 6 lines) File Management Commands

tail - - To display the bottom of a file. $ tail (by default it will display bottom 10 lines) $ tail -4 my_file (it will display only bottom 6 lines) File Management Commands

Filter Commands

Filter Command Com mand Name - - wc Purpose - - used to count the number of lines, words, characters of a given text or file. Opti ons - - - l  Count only the number of lines in a file - w  Count only the number of words in a file - c  Count only the number of characters in a file

Ex - - $ wc myfile 82 511 2313 myfile (lines) (words) (character) $ wc –l myfile 82 myfile (lines) Filter Command

Redirection

Redirection St andard input  Keyboard Standard output  Display Screen (Monitor) We can direct the input & output to other stream Command can be inputted from - - Keyboard A file (using redirection operator <, > and >>) By another command ( using the redirection operator | ). (|- pipeline Symbol)

Output can be send to - - Standard output (monitor) A file Another command Input Redirection Using operator Left chevron(<) Ex- - $ cat > f1 < f2 Redirection

Output Redirection Using operator Right chevron(>) Ex- - $ cat myfile > newfile (Write the contents of myfile to new file) Using operator ( >> ) Ex - - $ cat myfile1 >> newfile1 (Append the content of myfile1 with newfile1) Redirection

Connecting commands Using pipes ( | ) Ex- - $ ls | wc –l Counts the number of files and directories. Output of ls is piped to wc command. Ex- - $ who | wc –l Counts the number of active login users. Output of who is piped to wc command. Redirection

Session - 06 Objectives File permission Changing File permission Aim - -

File Permission

In UNIX/LINUX, there is a concept of user and an associated group The system determines whether or not a user or group can access a file or program based on the permissions assigned to them. Apart from all the users, there is a special user called Super User or the root which has permission to access any file and directory

There are three permissions for any file, directory or application program. The following lists the symbols used to denote each, along with a brief description: r — Indicates that a given category of user can read a file. w — Indicates that a given category of user can write to a file. x — Indicates that a given category of user can execute the file.

Each of the three permissions are assigned to three defined categories of users. The categories are: owner — The owner of the file or application. group — The group that owns the file or application. others — All users with access to the system.

One can easily view the permissions for a file by invoking a long format listing using the command ls -l. For instance, if the user user1 creates an executable file named test, the output of the command ls -l test would look like this: -rwxrwxr-x 1 user1 grp1 1251 Sep 26 12:25 test

The permissions for this file are listed are listed at the start of the line, starting with rwx. This first set of symbols define owner access. The next set of rwx symbols define group access The last set of symbols defining access permitted for all other users.

This listing indicates that the file is readable, writable, and executable by the user who owns the file (user user1) as well as the group owning the file (grp1). The file is also readable and executable, but not writable.

Changing permission Default permission of a file  rw-r--r-- Default permission of a directory  rwxr-xr-x Command to change the permission of a file or directory chmod <arguments> <file/ directory name>

chmod Arguments Category Operation Permission u (owner) + (assign) r (read) g (group) - (deny) w (write) o (other) = (absolute Assignment) x (Execute) a (all) Changing permission

chmod Example - - $ chmod u+x myfile  assign execute permission to user. $chmod g-w myfile  remove write permission to group. $chmod og-x myfile  remove the execute permission of other & group. $ chmod o-rwx myfile  remove the all permission of others. Changing permission

chmod Example - - $ chmod ugo=r myfile  assign read permission to user, group, other by removing other permissions. Octal notation Read Permission = 4 Write Permission = 2 Execute Permission = 1  777 signifies all permissions and 000 signifies absence of all permissions. Changing permission

chmod Example - - instead of $ chmod a=r myfile we can give $ chmod 444 myfile instead of $ chmod ugo=rw myfile we can give $ chmod 666 myfile Changing permission

Session - 07 Objectives Changing ownership Changing group ownership Umask File links Aim - - Linux permission changing commands

The creator became the owner of the file. Only owner can change the permissions of a file. The ownership of the file or directory can be changed using the command chown <owner> <file/directory name> Ex- - $ chown user4 myfile Grant the ownership of myfile to user4.  Ownership once surrendered cannot be re-established.

The group ownership of the file or directory can be changed using the command chgrp <group> <file/directory name> Ex- - $ chgrp grp2 myfile7 Grant the group ownership of myfile7 to grp2.  By default, the group owner of a file is also the group to which the other owner belongs.

Default file permission umask – system variable, decides the default file & directory permission. When the a file is created the permissions are set to File – rw-rw-rw- (666) Directory – rwxrwxrwx (777) Value of umask is subtracted from original value. umask – 022 For file - - 666 – 022 = 644 (rw-r--r--) For directory - - 777 – 022 = 755 (rwxr-xr-x)

Default file permission To change permission $ umask 044 $ cat > new contents $ 666 – 044 = 622 new (rw--w--w-)

Sticky Bit Sticky bit can be added to a directory to prevent the files within it from getting deleted. No one can delete the files from the directory except owner and the root user. To add sticky bit to a directory $ chmod o+t <directory name> $ chmod o+t ram (contents of ram directory will not get deleted by others)

Session - 08 Objectives File links Aim - - Linux file links

File Links Every file has inode numbers to identified by the system When we create a copy of a file then it will create two files with two different names and different inodes . When we make a link of a file then we have single file, different names, same content and same inode numbers. Links are of two types Hard links Soft links ( symbolic link)

Hard links The ln command is used to create multiple links of a file. Example $ ln stuff junk $ ls – i junk 1659 stuff

If we change the contents of stuff file those changes will appear in junk file and vice versa. If we delete one of the file. Then one of the link to that file will be deleted A file is truly deleted from the file system only when it has no links to it. By default a file has just one link. A directory contains two hard links . ( a link pointing itself) .. ( a link to pointing to its parent)

Symbolic link ( soft link) It is another type of link which is different from hard link. A symbolic link allows us to give a file another name, but does not link the file by inode number ln –s stuff sub The file having symbolic link have the permission rwxrwxrwx $ ls –l -rw-rw-rw- 2 user1 grp1 23 Jul 24 04:19 stuff lrwxrwxrwx 1 user1 grp1 5 Jul 24 05:33 sub  stuff $

Difference between hard link & soft link One can create a symbolic to a file that does not exist. The same is not possible with hard links. Symbolic links identifies the files they point to. But with hard links, there is no easy way to determine which files are linked to the same inode. You can hard-link files only when they are on the same file-system; symbolic links do not have this reflection.

File handling commands od – used to display data in octal format Also used for printing the non printable characters. -b – option used along with od to display each character separately -c – option used with –b option to display the character with octal code Each line of the output displays 16 bytes of data in octal, preceded by the position in the file of the first byte in the line.

$ cat > f3 rkcit college $ $ od f3 0000000 066551 062560 064562 066141 061412 066157 062554 062547 $ $ od -b f3 0000000 151 155 160 145 162 151 154 012 143 157 154 154 147 145 0000020 012 0000021 $

$ od -bc f3 0000000 151 155 160 145 162 151 154 154 012 143 157 154 154 145 147 145 i m p e r i a l \n c o 1 1 e g e 0000020 012 \n 0000021 $

Session - 09 Objectives File comparison Access modification time change Aim - - touch command

Comparing two files cmp – this comand is used to check whether two files are identical or not Syntax – cmp file1 file2 Compare two files byte by byte Example $ cat > f1 rkcit collegE $cat > f2 rkcit College $

$ od -b f1 151 155 160 145 162 151 141 154 040 143 157 154 154 145 147 105 $od -b f2 111 155 160 145 162 151 141 154 040 103 157 154 154 145 147 145 $cmp f1 f2 f1 f2 differ: byte 1, line 1 $cmp –l f1 f2 1 151 111 10 143 103 16 105 145

Common between two files comm - used to check the comm things in the files Both files should be sorted and also have some difference Syntax – comm file1 file2 The command displays three collumn output Contains Unique contents of first file Contains unique contents of second file Common contents of both file

$cat > f1 $cat > f2 apple ball Fruits grapes john john pass mike stel people xerox result $ stel uninor $

$ comm f1 f2 apple ball fruits grapes john mike pass people result stel uninor xerox

Modification and Access time Knowledge of a file’s modification and access time is important for the system administrator. Linux has the following time-stamps The time when the file was last modified The time when the file was last accessed touch command is used to change timestamp Modification time & Access time The time when change is made to contents of a file known as the modification time (ls –l) When a file is accessed, i.e. when it is read, write or executed. the accesses time is stamped on the file. (ls –lu)

-m – set to current date and time (modification) -a – set to current date and time (access) -t – set to specified date and time of both $ ls –l file1 -rw-r--r-- 1 user1 grp1 250 2011-08-03 11:50 myfile1 $ ls –lu file1 -rw-r--r-- 1 user1 grp1 250 2011-08-06 10:27 myfile1 $ touch -t 03151020 file1 $ ls –l file1 -rw-r--r-- 1 user1 grp1 250 2011-03-15 10:20 myfile1 $ ls –lu file1 -rw-r--r-- 1 user1 grp1 250 2011-03-15 10:20 myfile1

$ touch -t 201004201020 file1 $ ls –l file1 - rw -r--r-- 1 user1 grp1 250 2010-04-20 10:20 myfile1 $ ls – lu file1 - rw -r--r-- 1 user1 grp1 250 2010-04-20 10:20 myfile1 $ touch -t 7004201020 file1 $ ls –l file1 - rw -r--r-- 1 user1 grp1 250 1970-04-20 10:20 myfile1 $ ls – lu file1 - rw -r--r-- 1 user1 grp1 250 1970-04-20 10:20 myfile1

$ touch –a file1 $ ls –l file1 -rw-r--r-- 1 user1 grp1 250 1970-04-20 10:20 myfile1 $ ls –lu file1 -rw-r--r-- 1 user1 grp1 250 2011-08-06 01:50 myfile1 $ touch –m file1 $ ls –l file1 -rw-r--r-- 1 user1 grp1 250 2011-08-06 01:52 myfile1 $ ls –lu file1 -rw-r--r-- 1 user1 grp1 250 2011-08-06 01:50 myfile1

Session - 10 Objectives Vi editor Different modes Switching between modes Commands used in vi Aim - - working in a vi editor

VI editor Vi is the most popular text editor available in almost UNIX and LINUX systems. It is entirely different from other modern text editors vi uses different types of commands to perform different operations. Vi editor has three modes Command mode Input mode Ex mode

Modes of vi Command mode Where you place your commands, when we invoke vi editor we will initially placed in this mode. Input mode It also known as input mode In this mode we can add text to the file Ex mode Enables us to give commands at the command line.

Commands given in command mode h – move one character left l – move one character right k – move up j – move down G – move cursor to the beginning of the last line in the file #G – move cursor to the beginning of the # th line. i – insert text before the current cursor position I – insert text at the beginning of the current line a – append text after the cursor A – append text at the end of the current line r – replace one character

Commands given in command mode R – go on replacing characters until ‘esc’ key is pressed s – replace the character at the cursor with any number of characters o – open a new line below the current line O – open a new line above the current line x – delete one character at the cursor X – delete one character to the left of the cursor dd – delete the entire line D – delete reminder of line after cursor p – paste the delete text

Commands given in command mode . – repeat the last executed command u – undo the effect of the last command H – move to the first line on the screen M – move to the middle line of the screen L – move to the last line of the screen Ctrl + f – show the next screen Ctrl + b – show the previous screen

Commands given in Ex mode :w – save the changes you have made to the file :q – quit vi without saving changes :wq – save and quit :q! – force quit if ‘q’ does not work

SWITCHING BETWEEN MODES Ex mode command mode Input mode a A I I O o S s R r esc :w :q :wq :q! esc

Session - 11 Objectives Vi editor Commands used in vi Aim - - working in a vi editor

b – move back to the beginning of word e – move forward to the end of the word w – move forward to the beginning of the word yy-copy a single line J – join single lines Repeat factor To repeat a single command multiple times the vi editor provides the repeat factor mechanism. We have to prefix a number with the command to which we want to repeat. 3dd – delete 3 lines 5yy – copy 5 lines 4j - move 4 lines downwards

Searching ? = Search for the pattern in backward direction ?text / = search for the text in forward direction /text n = find next in same direction N = find next in opposite direction

Creating files in vi vi <filename> opens an existing file Creates a new file if it doesn’t exists

Saving lines to a new file . = specify current line $ = specify last line :1,5w <filename> :1,.w <filename> :.,$w <filename> :1,$w <filename>

Replacement :s :Address s/old/new :s/ rkcit / rkcit Changes the first occurrence of rkcit with RKCIT in the current line :s/ rkcit /RKCIT/g Changes the all occurrence of rkcit with RKCIT in the current line :1,5 s/best/worst It changes the first occurrence of best with worst from line 1 to 5. :1,$ s/worst/best/g Changes all occurrence of worst with best in the entire file

Inserting another file : r :r filename Inserting output of a command : r ! Command name :r ! ls – l

Session - 12 Objectives Vi editor Commands used in vi Aim - - working in a vi editor

Abbreviation Inserting auto text ( abb ) : abb rkc rkcit college Mapping Defining our own command :map ( ctrl+v )key command :map del x :map q l

Handling multiple files in vi Vi editor facilitates to work with multiple files symontenously $ vi one two three It will open one file To switch to next file : n To switch to previous file :N To switch between current & previous file :e# To switch to a specific file :e <filename>

Session - 13 Objectives User defined variables Escaping and quating Aim - - shell variables

All Linux shell contains a list of variables which are known as environment variables. We can define our own variables and also display the value with echo command by prefixing a $ (dollar) symbol. HOME  user home directory SHELL  contains shell of the user PATH  contains the list of directory name in which the executable file resides PS1  primary command prompt PS2  secondary command prompt LOGNAME  contains login name of the user. Shell variables

User defined variables $ a=120 $ echo $a 120 $ b=“ rkcit ” $ echo $b rkcit $ Shell variables

Escape and quoting mark can made to explicitly to a special character. difference between single quotes and double quotes Single quote – to omit the special meaning of any meta character Double quote – used in part of the command in which we don’t want to omit the meaning of meta character Ex- If we want to display * character with echo command it will display all the file names in the home directory. $ echo * (will not work) $ echo ‘*’ $ echo “*” $ echo \* Escaping & Quoting

$echo my home is $HOME My home is /home/user5 echo ‘my home is $HOME’ My home is $HOME echo “my login name is $LOGNAME” My login name is user6

- Back quote- to evaluate a command in the command line $ echo Current time is `date` Current time is Sat Aug 19 10:10:01 BDT 2011 $ echo “my current working directory is ` pwd `” My current working directory is /home/user3/ mohan $a=`date` $echo $a Sat Aug 19 10:10:10 BDT 2011

Alias – kourne and bourne shell provides a command alias to assign a short name to an existing command $alias p=pwd $p /home/user2

cut command Used to filter particular columns or fields out of a file. Options of cut -c = extract columns -f = extract fields - d = specify the delimiter (separator) Examples $ cut –c2 emp.lst $ cut –c 2,5,9 emp.lst $ cut –c 2,3,4,5,6 emp.lst Or $cut –c 2-6 emp.lst Filters and Regular Expressions

$cut –d “\t” -f4 emp.lst $ cut –d “|” –f2,5 emp.lst $cut –d ‘|’ –f2,5 emp.lst $cut –d \| -f2,5 emp.lst $ cut –c 10- emp.lst from 10 th character to end $cut –c -5 emp.lst from 1 to 5 $ cut –d ‘|’ –f3- emp.lst 3 to last $cut –d \| -f2 emp.lst > c1 Filters and Regular Expressions

Session - 14 Objectives Filter commands Aim - - provide knowledge about filter commands cut, grep, paste

Translating character (tr) This command is used to replace one character with another one at the time of displaying. $ tr ‘a’ ‘A’ < file1 $ tr ‘|’ ‘=‘ < emp.lst $ tr ‘|’ ‘\t’ < emp.lst Options of tr - d = we can delete a character at the time of displaying $tr –d ‘|’ < emp.lst $ls –l | tr –d ‘-’ Filters and Regular Expressions

-s = (squeeze) consecutive occurrence of the characters remove the Consecutive duplicate characters $tr –s ‘ ‘ emp.lst $ls –l | tr –s ‘ ’ | cut –d “ ” –f 3,5 Filters and Regular Expressions

grep command It means global regular expression and print. It searches for a pattern and display the selected lines containing the pattern $ grep good emp.lst $ grep cuttack emp.lst display all employees from cuttack $ grep sambalpur emp.lst emp2.lst $ grep “ sasank gupta ” emp.lst Options of grep command -I = ignore case -v = display the non-matching characters -n = display the line numbers Filters and Regular Expressions

-c = count the number of lines matching the pattern -l = display only the file name containing the pattern -e = specify multiple pattern -E = specify multiple pattern $grep ‘ctc > bbsr’ emp.lst grep –E ‘ctc|bbsr’ emp.lst egrep ‘ctc|bbsr’ emp.lst -f = specify the file name that containing the pattern Filters and Regular Expressions

sort command Arrange the files in a specific order Sort [option] <filename> Options -t = specify the delimiter -k = specify the field number -r reverse order -c = check whether the file is sorted or not. Filters and Regular Expressions

-u remove the duplicate line -o specify the output file in which the sorted information will store Sort –t “ ” –k 4 emp.lst Sort –t “ ” –k3,4 emp.lst Tab=`echo –e “\t”` sort –t “Tab” –k2 emp.lst Sort – t “ ” –c emp.lst Sort –t “|” –k2 –c emp.lst Sort emp.lst –o employee

Session - 15 Objectives Regular Expressions Aim - - provide knowledge about Regular Expressions

Regular Expressions If we want to match similar patterns with a single expression we can use the method of regular expression using the pattern matching concepts we can represent multiple expressions with a single pattern the regular expression is of 2 types and contain the own characters there own characters sets. Basic regular expressions (BRE) Extended regular expressions (ERE) Characters in Basic Regular Expressions * = zero or more occurrence of previous character $ grep de*pak emp.lst . = Any single character $ grep D.pa emp.ls t [abc] = match any character from the range $ grep g[ie]ta emp.lst [a-z] = match any single character from the range $grep BCA[0-9] emp.lst Filters and Regular Expressions

[^abc] = any character other than the list [^a-z] = any character other than the range ^a = line starting with character a ^[^R] = line doesn’t starting with R A$ = lines ending with character A List out all the directories. List out all the files Filters and Regular Expressions

Character sets in Extended Regular Expressions ERE makes it possible to match dissimilar pattern with a single expression. It uses some additional characters such as: +  it matches 1 or more occurands of previous characters ?  it match ‘0’ or ‘1’ occurance of previous characters Sed = It is a filter command like grep having some additional facilities than grep. It is known as the stream edition. It is a multipurpose tool having the features of several filter commands. $ sed option ‘address action’ filenames In address and action we can specify the line number and the commands for operation p  print the selected line q  to display the selected lines w  save selected lines to a new file $ sed ‘5q’ emp.lst (first 5 lines) $ sed ‘2,6q’ emp.lst ( display all by repeating from 2 to 6) Filters and Regular Expressions

$ sed ‘2,$5p’ emp.lst (all lines by repeating lines 5 and end of the files) -n  used to display selected lines $ sed -n ‘5,8p’ emp.lst $ sed –n ‘8,$p’ emp.lst $ sed –n ‘8,15!p’ emp.lst $ sed –n 3,5p >9,20p’ emp.lst $ sed –n ‘2,5 w new.txt’ mp.lst Filters and Regular Expressions

Session - 16 Objectives Sed command Shell Programming Aim - - provide knowledge about Regular Expressions, Shell programming.

Context addressing With context addressing mechanism we can address the lines by specifying a pattern. The lines containing the specified patterns will display. $ sed –n ‘/bgh/p’ emp.lst $ sed –n ‘/bgh/!p’ emp.lst $ sed –n ‘/sales/p >/cuttack/p’ emp.lst $ sed –n ‘/sales/w new’ emp.lst Substitution using sed s- substitute $ sed ‘s/old/new/g’ filename $ sed ‘5,15 s/ctc/cuttack/g’ emp.lst $ sed ‘/sales/s/ctc/cuttack/g’ emp.lst Filters and Regular Expressions

Deleting blank lines from a file Display name and address of employees who were from sambalpur from last 10 lines. Who | grep –c “^$LOGNAME” Filters and Regular Expressions

Shell script or shell programming is a mechanism to execute multiple commands in a group. when group of commands have to be executed regularly they should be stored in a file and the file itself executed as a shell script. The extension of shell program is .sh. When we execute the shell program it execute all the commands in it. We can execute a shell program with the command .sh Sh If a shell program has executable permission we can execute it directly Shell Script

Wap to display your name and address. $ cat > oca.sh /vi oca.sh echo STUDENTS OF BCA II echo rkcit College echo budharaja echo sambalpur Wap to display your login name, shell and Home directory expr = it is a command line calculator program through which we can perform calculations both numerical and string $ expr 5 + 6 $ a=100 $ b=200 $ expr $a + $b Shell Script

Wap to display the values of 2 variables clear x=10 y=20 echo value of x= $x echo value of y=$y Wap to add 2 numbers clear x=12 y=23 echo “addition =`expr $x + $y`” Or Z=`expr $x + $y` Printf “value of x=%d”$x Printf “value of y=%d”$y Printf “addition of %d & %d is %d”$x$y$z Shell Script

Session - 17 Objectives Shell Script Read Command line arguments Conditional statement If else case Aim - - provide knowledge about shell script

read = used to take input from the user Wap to input one no & display its value clear echo “Enter a number” read a Printf “value of x=%d”$a Wap to input two numbers and display them clear echo “enter 1st number” read a echo “enter 2 nd number” read b c=`expr $a + $b` printf “addition of %d & %d is %d”,$x$y$z Shell Script

Command line Argument means the information we provide to the system The information with the command in the command line is known as command line argument Shell program accept the arguments from the command line. Shell uses different variables to manage the command line $@ / $* = display the list of arguments $# = display the no of arguments $1 $2 $3 $4 ……….$n = represents positional parameters in the command line Shell Script

$ set rkcit bca 2 nd 100 $ ech o $* Imperail bca 2 nd 100 $ echo $# 4 $ echo $1 rkcit $ echo $2 bca Wap to display the addition of 2no’s provided in the command line? (add.sh) a=$1 b=$2 c=` expr $a + $b` echo $c $ add 120 150 270 $ sh add.sh 100 200 300 Shell Script

Conditional Statements The shell script allows to implements the conditional statement for conditional execution with the help of following two techniques: if Statement case Statement if statement Syntax : if command then execute the command else execute the command fi Shell Script

Wap to display a message if the pattern is found. $ cat > search1.sh if grep ‘manager’ emp.lst > /dev/null then echo “pattern found” else echo “pattern not found” fi Exit stats of a command = success or failure of execution of a command is known as exit status. The state is “0” in case of success The state is any non-zero value in case of failure The $? Variable contains exit status of last executed command. Shell Script

$ cat oca $echo $? test = used to check whether a condition is true or false We can use this command to evaluate a condition $ test 5<10 $ echo $? Operators used in shell programming -eq =equals to -gt = greater than -lt = less than -ge = greater than equals to -le = less than equals to -ne = not equals to Shell Script

Wap to input 2 numbers and display the biggest one echo “enter two numbers reand a,b if test $a –gt $b then echo $a is big else echo $b is big fi Shell Script

echo “enter two numbers reand a,b if test $a –gt $b then echo $a is big else if then $b –gt $a then echo $b is big else echo both are same fi fi Shell Script

elif = incase of nested if else we can use elif. Here no need to specify multiple fi echo “enter two numbers reand a,b if test $a –gt $b then echo $a is big elif then $b –gt $a then echo $b is big else echo both are same fi fi Shell Script

Wap to check whether a number is even or odd echo “ enter a numbers” read a b=`expr $a % 2` if test $b -eq 0 then echo no is even else echo no is odd fi [ ] is substitute if test command If test `expr $a % 2` -eq 0 If [ `expr $a % 2` -eq 0] Shell Script

Session - 18 Objectives Multiple conditions And & or Operator Conditional statements Case Aim - - provide knowledge about shell script

Contents of /etc/ passwd file This file contain the information about the users in it. A database is mentioned in this file to store the user information. It contains a line of information for each system user Such as : User name Password Userid Group id Full name Home directory Shell user1:x:1001:1002:user1,,,,,:/home/user1:/bin/bash /etc/shadow= contains the character “x” In the password field. The user password is stored as encrypted string of 13 characters in the file /etc/shadow.

The file contains the password fields in an expanded format such as : User name Password Password last change Minimum number of date between password change Maximum number of date password is valid Number of days to warn the user to change password Number of days the login may be inactive Date when the login is no longer valid A reserve field for future used

Wap to input your login name and display its full name if user name doesn’t exists display a error message echo “enter the login name” read ln grep ln /etc/passwd > x1 if [ $? –eq 0 ] then a=`cut –d “:” –f5 x1 echo full name=$a else echo “invalid user” Shell Script

Multiple conditions We can use multiple conditions with –a for and operator and –o options for or operator Biggest among 3 numbers echo “enter 3 numbers” if [ $a –gt $b –a $a –gt $c ] then echo “$a Is big” elif [ $b –gt $a –a $b –gt $c ] then echo “$b is big” else echo $c is big fi Shell Script

Session - 19 Objectives Conditional statements Case Aim - - provide knowledge about shell script

Wap to input a single digit and display it in words Case statement case expression in pattern 1) command;; pattern 2) command;; … … *) command;; esac

Wap to input a digit and display it in words echo enter a digit read a case $a in 0) echo zero;; … … *) echo invalid digit;; Wap to input a character and check whether it is a vowel or consonant Wap to check whether it is an alphabet, digit or special symbol.

Session - 20 Objectives String comparison Looping Aim - - provide knowledge about shell script

String comparision = are used to compare two strings != not equals to Wap to input 2 strings and check whether they are equal or not echo “input 1 st string” read a echo “input 2 nd string” read b if [ $a = $b ] ;then echo “ strings are equal” else echo “strings are not equal” fi

&& and || two conditional operators Command 1 && command 2 In the above case the command2 executes in the success of command1 $ cat new.txt && date $ grep ‘sales’ emp.lst && echo found Commmand 1 || command 2 In the above case command 2 executes in the failure of command 1 $ cat new.txt || date $ grep ‘sales’emp.lst || echo “not found”

Looping in shell script Shell script provides 3 types of loops While For Until While loop while condition is true do commands ---- ---- done

Wap to display a name five times clear a=1 while [ $a –le 5 ] do echo “ rkcit ” a=` expr $a + 1` done Wap to display addition of all numbers from 1 to 50 Wap to display even numbers from 99 to 250 Wap to input a number & display the addition of all digits Wap to input a number and display each digit in word Wap to input a number and check whether it is prime or composite Wap to display all prime numbers from 200 to 500 Wap to check whether a number is strong or not?

Session - 21 Objectives Shift command Aim - - provide knowledge about shell script & procwess

Shift command Shift the positional parameters to left $ set 10 hari 9 th 1 st $ echo $1 10 $ shift $echo $1 hari Or clear n=$# a=1 while [ $a -le $n] do echo $1 shift done

Session - 22 Objectives AWK Aim - - provide knowledge about shell script & procwess

Wap to display the addition of all the command line arguments? wap to add new records to employee data base? clear echo “enter employee id” read id echo “enter employee name” read nm echo “ enter employee address” read ad echo “enter employee salary” read sal echo “$id | $nm | $ ad” >> emp.lst

A process is simply an instance of running program. a file is treated as a simple file when it lies in a dormant state. It can also be treated as a process when it is under execution Like human beings processes are born, they give birth of to another process and also die. A process is said to be born when the program starts its execution. It remains alive as longer the program is active. After execution is completed the process is said to be dead. It Is the kernel but not the shell that is ultimately responsible for the management of the processes. It determines the time and properties that are allocated to a process. So that multiple processes can share a single CPU. Like files processes are also have some attributes. All the attributes of processes are maintained by the kernel and stored in the process table known as PCB (Process Control Board). Process

Attributes of PCB PID = > each process can be uniquely identified by an integer values known as PID. The PID number is assign to a process during the start of the execution. PPID = > this is the process of the parent process other than the properties there are some additional associated with the process such as :- Process name Terminal name Priority Born time CPU time Status When we logon to the Linux shell processes immediately created by the kernel which is known as login process. This process represents a linux command which may be sh, ksh, csh,etc. Any command that we type at the command prompt is actually the standard input to the shell process. The shell process remains active until we logout. Process Control Board

PS command Each process is associated with some attributes such as pid number, ppid number, user id number, execution time, terminal name, etc To display the attributes associated with the process we can use the command PS.

PS command Each process is associated with some attributes such as pid number, ppid number, user id number, execution time, terminal name, etc To display the attributes associated with the process we can use the command PS.

Killing process The linux system requires to communicate with the process, we can send a signal to a process Each signal is identified by a number and designed to perform a specific operation If a program is running longer than the expected time, we want to terminate an executing program we can use the command kill. Syntax $ kill option pid_numbner Option -9 = we can use this option to kill the process force fully.

NICE Linux can run a lot of processes at a time, which can slow down the speed of some high priority processes and result in poor performance. To avoid this, you can tell your machine to prioritize processes as per your requirements. This priority is called Niceness in Linux, and it has a value between -20 to 19. The lower the Niceness index, the higher would be a priority given to that task. The default value of all the processes is 0. To start a process with a niceness value other than the default value use the following syntax nice -n 'Nice value' process name

DF This utility reports the free disk space(Hard Disk) on all the file systems.

System Call A  system call  is a mechanism that provides the interface between a process and the operating system. It is a programmatic method in which a computer program requests a service from the kernel of the OS. System call offers the services of the operating system to the user programs via API (Application Programming Interface). System calls are the only entry points for the kernel system. An operating system can roughly be divided into two modes: Kernel mode:  A privileged and powerful mode used by the operating system kernel User mode:  Where most user applications run

Why do you need System Calls in OS? Following are situations which need system calls in OS: Reading and writing from files demand system calls. If a file system wants to create or delete files, system calls are required. System calls are used for the creation and management of new processes. Network connections need system calls for sending and receiving packets. Access to hardware devices like scanner, printer, need a system call.

Types of System calls Process Control File Management Device Management Information Maintenance Communications

Important System Calls Used in OS wait() In some systems, a process needs to wait for another process to complete its execution. This type of situation occurs when a parent process creates a child process, and the execution of the parent process remains suspended until its child process executes. The suspension of the parent process automatically occurs with a wait() system call. When the child process ends execution, the control moves back to the parent process.

fork() Processes use this system call to create processes that are a copy of themselves. With the help of this system Call parent process creates a child process, and the execution of the parent process will be suspended till the child process executes.

exec() This system call runs when an executable file in the context of an already running process that replaces the older executable file. However, the original process identifier remains as a new process is not built, but stack, data, head, data, etc. are replaced by the new process. kill(): The kill() system call is used by OS to send a termination signal to a process that urges the process to exit. However, a kill system call does not necessarily mean killing the process and can have various meanings.

exit(): The exit() system call is used to terminate program execution. Specially in the multi-threaded environment, this call defines that the thread execution is complete. The OS reclaims resources that were used by the process after the use of exit() system call.

Shell SHELL  is a program which provides the interface between the user and an operating system. When the user logs in OS starts a shell for user.  Kernel  controls all essential computer operations, and provides the restriction to hardware access, coordinates all executing utilities, and manages Resources between process. Using kernel only user can access utilities provided by operating system.

C Shell Denoted as csh Bill Joy created it at the University of California at Berkeley. It incorporated features such as aliases and command history. It includes helpful programming features like built-in arithmetic and C-like expression syntax. In C shell: Command full-path name is /bin/ csh Non-root user default prompt is hostname % Root user default prompt is hostname #

Bourne Shell Denoted as sh It was written by Steve Bourne at AT&T Bell Labs. It is the original UNIX shell. It is faster and more preferred. It lacks features for interactive use like the ability to recall previous commands. It also lacks built-in arithmetic and logical expression handling. It is default shell for Solaris OS. For the Bourne shell the: Command full-path name is /bin/ sh and / sbin / sh Non-root user default prompt is $ Root user default prompt is #.