Escolar Documentos
Profissional Documentos
Cultura Documentos
of UNIX
SAMPATH 1
Chapter 1
UNIX Operating System
SAMPATH
Objectives
In this session, you learn about: The functions of OS The history of Unix The features of UNIX The Unix architecture Process management File management
SAMPATH
OS can be defined as an organized collection of software consisting of procedures for operating a computer
OS provides an environment for execution of programs OS acts as an interface between the user and the hardware of the computer system.
SAMPATH
Operating System
Operating system interacts with user in two ways Operating system commands Enables user to interact directly with the operating system. Operating system calls Provides an interface to a running program and the operating system. System calls in UNIX are written in C.
SAMPATH
History of UNIX
Ken Thompson of AT&T Bell Laboratories designed UNIX in late 1960s
Two versions of UNIX that emerged are AT&T Unix and BSD Unix
In 1989, AT&T and Sun Microsystems joined together and developed system V release 4 (SVR4) Two of the main standards mainly in use are POSIX (Portable Operating System Interface) and X/open standard. In 1988, MIT formed Xconsortium developed vendor-neutral Xwindow System.
SAMPATH 6
Features of UNIX
UNIX is multi tasking and multi user operating system UNIX is a character user interface (CUI ) operating system UNIX is a open source operating system Portability Can we use it on any OS Modularity Can change the source code File structure Security Strong networking support & advanced graphics
SAMPATH
Layered Architecture
banner ls
kernel hardware
sort
sh who a.out
vi
ed
date grep
wc
SAMPATH
Layers
SAMPATH
Shell
Acts as an interface between user and kernel User commands will be interprets and carried out to kernel. Its features include control flow primitives, parameter passing, variables and string substitution.
SAMPATH 10
Kernel
Kernel will act as a interface between shell and hardware components. Core of the operating system Collection of system calls mostly written in C language Interacts directly with the hardware Allocates time and memory to programs and facilities IPCs Helps in I/O services,
SAMPATH 11
/root
/etc
/bin
/usr
/dev
/lib
/tmp
12 SAMPATH
/etc
stores the system administration utility files stores the most commonly used unix commands stores all user home directories and some Unix commands
/bin
/usr
/dev
/lib /tmp
13 SAMPATH
rwx group
rwx other
A
3 sampath nipuna 2080 oct 10 09:34 mydoc.doc
14
SAMPATH
15
SAMPATH
Absolute mode
Based on octal numbers No access 0 Execute access only 1 Write access only 2 Read access only 4 Write and execute access 2+1= 3 Read and execute 4+1= 5 $chmod 400 mydoc.doc Exercise Write the command to change the permission of the file mydoc.doc Read and write for the owner Write and execute for the group Execute only for others ( both in symbolic and absolute)
16
SAMPATH
cat command
Helps you to create a file $ cat > filename cat filename helps to view the contents of the file.
touch command
-- Will allow to create multiple 0 byte files $ touch file1 file2 file3
VI command
$ vi <filename> If the file doesnt exist, it will create otherwise open the existing one.
17 SAMPATH
Creating a directory
You can create a directory by using the mkdir command. For example, to create a directory named dir1 within the current working directory:
$ mkdir dir1 $ mkdir /usr/user1/dir1 Options
cd command To change the directory to dir1 type cd dir1 pwd To see the current working directory
18
SAMPATH
Removing a directory
Removes a directory To remove a directory
Must be empty Should not be the current directory or at a higher level Should not be the home directory -p -> Removes all directories along the path name specified $ rmdir -p /home/demo/mydir
19
SAMPATH
Removing files
To delete a file
$ rm <file_name>
20
SAMPATH
dot
list the inode number in the first column sorts in multi column output across the page displays file in columns recursively list all directories and subdirectories indicates the type if files using symbols
-ld
21 SAMPATH
22
SAMPATH
wc
wc word count
-c character count -w word count -l line count $ wc employee To count the number of files in a directory To count the number of users currently logged in WC l file1 WC c file1 Wc w fil1
23
SAMPATH
tr
Translates the input into some other form Eg: Convert all lowercase to uppercase
tr [a-z] [A-Z] file1
24
SAMPATH
FIND
find command
Helps to find a file in the specified directory The syntax is find <path> -name <filename> find . name doc1.doc find . /tmp/project name new_data find /usr type d name backup
25
SAMPATH
File Comparisons
comm : displays common lines in the two files cmp : to compare two files diff : reports the difference between two files uniq : display the duplicate and unique lines of a file
26
SAMPATH
comm
Customer A Navneet Neeraj Ritu Jamil Richa Rachna Ritu Neeru Joby Seema customer B
Ritu
27
SAMPATH
cmp
Compares two files $ cmp file1 file2 Eg: document1 document2 This is a document. This a document. $cmp document1 document2 document1 document2 differ : char 6, line 1
28
SAMPATH
diff
$ Reports the difference between two files diff [options] [file1][file2] -b ignore trailing blanks -h used for files of unlimited length file1 cal cp crypt z $ diff file1 file2 4c4 <z ---->cut file2 cal cp crypt cut
Eg:
29
SAMPATH
uniq
Displays the duplicate and unique line of a file $ uniq [option..] <filename>
-u display only the unique lines -d display only the duplicate lines -c display all lines each preceded by the count of the records.
30
SAMPATH
uniq
Emp.dat E001 Shagufa C005 MKT E002 Shekhar C001 MKT E004 Anurag A001 PROD E004 Anurag A001 PROD E005 Madhu A002 ADMIN E005 Madhu A002 ADMIN $uniq emp.dat ( avoids duplicate lines, E004 and 5 are printed only once)
31
SAMPATH
32
SAMPATH
33
SAMPATH
Input redirection
Changing the default input source Input redirection operator < $ command <filename After the execution the standard input is reassigned to the default device Eg :
$ cat <emp.dat ( similar output will be displayed by cat emp.dat)
34
SAMPATH
Output redirection
Changing the default destination of the output The output redirection operator : > $ command > filename After the execution the standard output is reassigned to the default device Eg:
$ cat emp.dat > emp.out $ date > todays_date $ cat > file1 $ cat >> file2
35
SAMPATH
36
SAMPATH
37
SAMPATH
Filters: grep
grep ( global search for regular expression and print) grep is the standard file searching and selection utility $ grep [options] pattern <filename> Options :
-n : prints line numbers -v: the reverse search criterion -c: display only a count of matching patterns
38
SAMPATH
grep
grep madhu emp.dat
Display the line(s) containing the string madhu.
39
SAMPATH
sort
sort [options] [-o output file name] [file name] options
d letters, digits and blanks n sort on the numeric field r reverse sort u eliminate duplicate lines t filed separator o stores the output
40
SAMPATH
cut
Retrieves selected fields from a file $ cut [options] <filename> Options
-c selects characters specified by list -fselects fields specified by list -d field delimiter
41
SAMPATH
cut
$ cut c4-9 employee
Display characters 4 to 9 from each record
$ cut f 4- employee
Display 4th field onwards
42
SAMPATH
paste
Merges files horizontally. $ paste <file1> <file2> Options d delimiter
43
SAMPATH
44
SAMPATH
Others
SAMPATH
45
Information on all the commands can be found in the on-line manual pages. $man <command> Shows the details (syntax and description) of the command help, info
46
SAMPATH
vi
$ end of the current line ^ or 0 beginning of the current line w beginning of the next word W same as w, but ignores the punctuation b back to the beginning of the current word e end of the current word
47
SAMPATH
vi
Moving the cursor over the paragraph { to the beginning of the current paragraph } to the end of the current paragraph n{ nth paragraph above the current paragraph n} nth paragraph below the current paragraph Moving the cursor over sentences ( first character of the sentence ) last character of the sentence
48
SAMPATH
Screen movements
Ctrl+D scrolls down half a window Ctrl+U scrolls up half window Ctrl+B moves to the previous window Ctrl+F moves to the next window What is the command to move the cursor to the right by five words?
49
SAMPATH
50
SAMPATH
Modifying text
r, R cw ncw cc ncc c$ replace character change current word change n words change current line change n lines changes remainder of the line
51
SAMPATH
P , p copy the contents of the current buffer U undo all changes to the current line u undo the last command
52
SAMPATH
Thank You
SAMPATH
53