Beruflich Dokumente
Kultur Dokumente
Road Map
Recap of Day 2 To understand Unix Utilities. To understand Program development tools. To understand communication commands. To understand the security features.
To understand Unix Utilities. To understand file compression utilities. To understand Unix Program development tools To understand C Program Development Tool make SCCS To understand Unix Communication Tools. To understand commands like write, wall, etc. To understand security features Passwords File Permissions Directory Permissions SU Command
Unix Utilities.
gzip Utility for compression of files. Files have an extension of .gz. Syntax gzip file_name To restore the file back, we need to use gzip d file_name or gunzip file_name
gzip gzip reduces the size of the named files using Lempel-Ziv coding (LZ77). Whenever possible, each file is replaced by one with the extension .gz, while keeping the same ownership modes, access and modification times. Example $> ls -l abcd1 -rw-rw-r-# For finding the details of file abcd1 1 ajit ajit 255 Mar 17 15:45 abcd1 # Size of the file is 255 bytes. #Zipping the file. File would have an
-rw-rw-r-- 1 ajit ajit 51 Mar 17 15:45 abcd1.gz Size of the zipped file is 51 bytes. To unzip $> gzip -d abcd1
Unix Utilities.
tar Tape Archive.
Copies files to or restores files from tape. Syntax tar [options] files.
tar If any of the files are directories, tar acts on the entire subtree. Options need not be preceded by -. Function Options (choose one) c r t u x files) Example To backup 'trng' dir, create an archive file 'trng.tar : $> tar -cvf trng.tar trng Note : c - create, v - verbose mode, f - archive to file. Instead of 'f', you can mention a device name too, like tape device. To extract it back from the archive file: $> tar -xvf trng.tar Note : The archive file can have any or no extension. All that 'tar' does is, concatenates all the files into archive file and it doesn't compress the archive file (like WinZip & other utilities). So, it's a good idea to use 'gzip' to compress the archive file before actually backing it up. create a new tape Append filesto tape Print the names of files if they are stored on tape Add files if not on tape or if modified Extract files from tape (if files not specified, extract all
Program
awk String processing, report generation, file editing C General purpose and system programs; fast executing programs efl Writing structured FORTRAN programs Fortran 77 Number-crunching; engineering, statistical and mathematical applications; fast executing programs sh General purpose programs; file manipulation; process control sno Pattern matching; string manipulation (SNOBOL)
ER/CORP/CRS/OS31/003 Version No: 2.00
One of the primary goals of the Unix operating system design was ease of application program development. As such the Unix system offers a wide assortment of programming languages and development tools. The nature of the application would determine the choice of a language. In most cases there is a trade-off between development time versus execution speed. It is not uncommon for the shell itself to either control the execution of other programs, or do a lot of processing itself. A shell script is shorter and takes less time to develop than an equivalent C program but runs more slowly because it is interpreted rather than compiled.
Unix
C Program Development
C Program Development.
cc C language Compiler
Phases in creation of executable program.
Source Code
.c
Object Code
.o
Executable code
a.out
Copyright 2004, Infosys Technologies Ltd 7 ER/CORP/CRS/OS31/003 Version No: 2.00
Example $> cc file1.c creates an executable file by the name a.out Compiles the file file1.c. $> a.out Executes the file #Compiles and
cc - Important options
-c
Compiles the given C file. No linking would be done. Syntax
cc c <filename.c>
-o
Specify a given name for the final executable file. Syntax
cc o <file1> <filename.o>
cc -c Compiles the given file and creates an object code. Examples $> cat demo1.c main() { printf( \n Hello \n"); } $> cc -c demo1.c Creates an object code by name demo1.o cc o Allows to create an executable file by the name requested by the user. Examples $> cc -o demo1 demo1.c name demo1 $> demo1 #Execute the file demo1 Hello #Output #Creates an executable file by the
Development Tools.
Debuggers
adb - assembly debugger ctrace - tracing execution statement by statement sdb - symbolic debugger
Beautifier
cb - Automatic formatting of C programs
Development Tools.
cflow
Generating a flow graph of external references
lint
Checking (that may span many files) for bugs or non-portable uses of the language
prof
Obtains performance statistics
10
10
11
11
make
How it works?
Works on concept of Dependency Maintenance. Picks up a file containing dependency relation among all the files, often called as makefile. Keeps automatic tracking of the source files that may been changed since the last compilation and causes their recompilation when necessary. automatically re-links the object modules to update the final executable.
12
12
make.
Benefits.
Lots of compilation time is saved. Picks up the latest version of the file. Avoids ambiguity over decision of which file to compile if a file content in a project system is changed.
13
If the project contains multiple files, make utility avoids compiling all the files together, thereby reducing the time spent on compiling. It only recompiles the file on which changes were made.
13
makefile
When a make command is issued, by default picks-up a file known as the makefile or Makefile. It contains the dependency relation for the different files in the system. The user could also customize the name of the makefile as per choice.
make f mymakefile
14
14
Makefile Contents.
Names of the source files that make up the program system. Name of the destination file. Information on how to regenerate the program system.
15
Example $> cat makefile OBJECTS = try.o add.o sub.o #Three object files make this system : try.o, add.o and sub.o final: $(OBJECTS) # The executable would be called final. cc $(OBJECTS) -lm -o final try.o: try.c common.h # For creating try.o, we require 2 files .i.e try.c and common.h add.o: add.c common.h # For creating add.o, we require 2 files .i.e add.c and common.h sub.o: sub.c common.h # For creating sub.o, we require 2 files .i.e sub.c and common.h $>
15
SCCS.
SCCS Source Code Control Systems. SCCS is a package of programs
to help manage the development and maintenance of large programs. to automatically track changes between versions of a program. to maintain a list of these changes which has the ability to quickly recreate a particular version on request. that does not waste much of disk space.
16
SCCS is a Version Control System. Version Control System is required to keep track of the different changes made in the system, so that as per business requirement, the user could revert to the earlier version of the system.
16
all SCCS files must begin with s. admin command must be run separately for each file that is to be placed under SCCS.
17
Example $ admin -n -i main.c s.main.c -n means new -i means install for the first time places main.c under SCCS calling it s.main.c To place many files under SCCS Use the for statement in a shell script for f in *.c do admin done After placing the files under SCCS, the original file must be removed to ensure the consistency of the contents of the version controlled file. -n -i$f s.$f
17
18
Examples. Display latest version with info: $ get -p s.main.c Extract for viewing but not editing $ get s.main.c Extract for editing $ get -e s.main.c
18
Syntax
$ delta s.main.c
19
19
20
20
21
21
Unix
Communication Commands
22
Communication Commands.
write mesg wall ftp telnet
23
Unix Operating System has several Commands by which one user can communicate to others.
23
write Command
Writes to another user logged in. Can be used by any user. Usage
$ write userid [tty]
24
Example $> whoami pract1 $> write pract2 This is a demo. user pract2
24
mesg command
To change permission for receiving messages. Usage
mesg [y/n/ ]
25
Mesg mesg y -- gives permission mesg n -- denies permission mesg -- reports current status Example: $> mesg is y $> mesg n from normal users. $> mesg is n Note : Even if a user chooses option n, then too he would receive the messages from the root. #Disables receiving of messages #Displays the status
25
wall command
writes to all users currently logged in Usage
- wall [-g group] message
26
Example $> wall This is a demo" $> Broadcast message from ajit (pts/0) (Sun Jul 11 15:32:51 2004): This is a demo
26
27
27
get
This command is used to transfer a file from destination terminal to source terminal. get filename
28
Multiple files can be selected in one command line and for that mput and mget commands are used. $> mput a* #Transfers all filenames starting with a from the source machine to the destination machine. $> mget b* #Transfers all filenames starting with b from the destination machine to host machine.
28
telnet.
Used for connecting to Unix Server. Usage
- telnet [hostname]
telnet 192.168.158.11
Server
Authenticated
29
The character typed on keyboard will first go to UNIX server and then return to the user terminal to be displayed on the telnet window.
29
Unix
Security Features
30
31
/etc/passwd can be viewed by a normal user. /etc/shadow cannot be viewed by a normal user.
31
32
/home/ajit>cat /etc/passwd root:x:0:4:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin trng39:x:542:504::/home/trng39:/bin/bash eugene:x:554:504::/home/eugene:/bin/bash trng90:x:594:504::/home/trng90:/bin/bash trng91:x:595:504::/home/trng91:/bin/bash trng92:x:596:504::/home/trng92:/bin/bash
32
33
$> cat /etc/shadow root:$1$lduGqK0k$fVDdj4J7zPvrcGefrXOf5/:12487::99999:::: bin:*:12227:0:99999:7::: daemon:*:12227:0:99999:7::: trng90:$1$22RPkY9l$SLMEVhOc1JoRMIOdBRj9D.:12332:0:99999:7::: trng91:$1$Z6f2.MP7$jhFco/./JuMBzDkkErAgo/:12332:0:99999:7::: trng92:$1$kbD4fCFI$3mlc37uMa4eAOFJL4sfFy1:12332:0:99999:7::: trng93:$1$wvhu.RmA$46MpC2jOYZbdOzt6ejiA41:12332:0:99999:7:::
33
34
34
The password entered would not be displayed, even in masked characters (like *,#,etc), on the screen. Prompts for current password.
35
Example $>passwd Changing password for user ajit. Changing password for ajit (current) UNIX password: New password: Retype new password: passwd: all authentication tokens updated successfully.
35
File Security.
Classes of users for a file.
Owner Group Others
36
Each type of user has 3 different permissions for a file. Hence for every file there are 9 composite permissions, which is identified by the 9-bit field for every file.
36
File Security.
Two modes of setting file permissions
Absolute Mode (Octal Integer) Symbolic Mode (String)
37
37
38
The read (r) permission is assigned the value 4. The write (w) permission is assigned the value 2. The execute (x) permission is assigned the value 1. - indicates no permission has been set. Example rwxrw-r-- indicates the owner has read, write and execute permissions; the group has read and write permissions; others have only read permission.
38
39
39
40
40
41
chmod Example $> chmod 777 com1 $> ls -l com1 -rwxrwxrwx $> ls -l com1 -rwxrwxrwx 1 ajit ajit 87 Jan 19 14:33 com1 1 ajit ajit 87 Jan 19 14:33 com1 #Symbolic Mode $> chmod ugo+rwx com1 #Absolute Mode
41
42
42
43
43
44
Directory Permissions. r permission only Can only list the contents of the directory, nothing else is possible. w permission only No listing files, no cd, nothing can be done on that directory! x permission only Can enter into the directory, but nothing can be done on that directory w and x permissions only Everything is possible, except listing of files. r and x permissions only Cant create a new file, can edit or delete an existing one either. It makes sense to deny write permission on a directory to others. r and w permission only Nothing is possible because cant enter into the directory, same as giving write permission alone. So, the ideal directory permission would be: drwxr-xr-(Value 754 octal) Full powers for the owner. No modification or creation of files by group, only execution and listing. Others get just listing of directory only.
44
Changing Ownership.
chown
Changing ownership for a file. Can be done only by the root or administrator. Syntax chown username file.
45
chown Examples $> ls -l demo -rw-rw-r-1 ajit_nair ajit_nair 11 Jan 17 14:02 demo #The owner name of file demo is ajit_nair
$> chown sujith demo #Converting the owner name from ajit_nair to sujith $> ls -l demo -rw-rw-r-1 sujith ajit_nair 11 Jan 17 14:02 demo #The owner name is sujith
45
Changing Group.
chgrp
Changing group for a file. Can be changed by the owner of the file. Syntax chgrp groupname file.
46
chgrp Examples $> ls -l demo1 -rw-rw-r-1 ajit_nair ajit_nair 11 Jan 17 14:02 demo1 #The group name of file demo1 is ajit_nair
$> chgrp sureesh demo1 #Converting the group name from ajit_nair to sureesh $> ls -l demo1 -rw-rw-r-1 ajit_nair sureesh 11 Jan 17 14:02 demo1 #The group name is sureesh
46
su command.
su Substitute user-id. An user can login as super-user without the need of logging off from the system.
47
The su (Substitute User-id) command switches a user to Super User without having to logout and is equivalent to logging in as root. It requires that the user should know the password of the root. $> su
47
Summary
Compression utilities. Different Development Tools. make. SCCS. Communication Tools. File Security.
48
48
Thank You!
Copyright 2004, Infosys Technologies Ltd 49 ER/CORP/CRS/OS31/003 Version No: 2.00
49