Sunteți pe pagina 1din 119

Solaris/Unix Training

Solaris/Unix Training Agenda


Overview of Unix (Day 1 ) Solaris commands(Day 1) vi (Day 2) Unix Architecture (Day 2) - Kernel - File Systems - Processes - Memory management Essentials of Solaris Administration (Day 2) Unix Performance monitoring (Day 2) Shell programming (time permitting)

Overview of Unix - History


Bell Labs joins with GE and MIT to develop Multics (1965) Ken Thompson also developed a new language called B. Denis Ritchie developed C language from B. Ken Thompson and Dennis Ritchie develop Unix (1970) In 1973, Unix was re-written in C language. This led to its popularity. AT&T could not sell Unix Thompson and Ritchie publish paper. Berkely starts the BSD program (1974) First licensed version of BSD Unix released (1975) DARPA uses BSD Unix for production projects (late 70s) AT&T first markets Unix. Sun Microsystems is founded (1982).

Overview of Unix - History


Sun Microsystems introduces SunOS (1983) 100K Unix sites worldwide (1984) AT&T and Sun start work on SVR4, unified version of Unix (1988) Open Software Foundation and Unix International formed (1988) AT&T releases System V, Release 4 (1989) OSF releases OSF/1 (1990) AT&T forms USL, sells to Novell (1993) Sun introduces Solaris (1992)

Overview of Unix History of Solaris


Product SunOS SunOS 4.1.4 Solaris 2.5 Solaris 2.6 Solaris 7 Solaris 8 Solaris 9 Solaris 10 When 1983 - First version 1994 last BSD based version 1995 1997 1998 2000 2002 2005

Overview of Unix
Various Unix Flavors: Product Solaris AIX HP-UX Linux Tru64Unix IRIX SCO Unix From Sun IBM HP RedHat, Suse, Fedora, Debian/Gnu, etc. Compaq SGI SCO

Others Dynix (Sequent), DGUX (Data General), etc.

Overview of Unix
TODO: - Login to 10.2.232.203 telnet 10.2.232.203 (username: devi passwd: 123456) uname a id (Userid and Groupid) Change your passwd : passwd echo $SHELL env | more env | grep SHELL

Overview of Unix
Multi User More than one user can access the system - who

user1 UNIX OS user3 user2

Overview of Unix
Multi Processing Number of processes can run at a time. Example: you can write Scripts, Functions and also you can do a print job in the background, Browse the net.,etc - ps ef (to see all processes running)

Provides virtual memory support Devices are treated as files Provides more than one type of shells (command interpreters)

Overview of Unix
Provides more than one mechanism for inter-process communication (IPC) . Excellent networking support through TCP/IP. The standard Unix File system is fast, but not very robust many vendors have introduced their own robust versions. Most system operations depend upon the configuration files such as /etc/passwd, /etc/group, /etc/hosts, /etc/services etc. Default system security can be enhanced through installation of additional security packs. Supports the X-Window system as a GUI.

Unix Architecture
Utility, command or shell script shell
User Mode Kernel Mode

system calls
File System
Kernel

I/O System

Memory Manager

Scheduler

Buffer Cache

Interrupt and Exception Handlers

Overview of Unix - Shell


Displays a prompt where the user can enter a new command.

Validates the command entered by the user.


Creates a new process using fork() or similar system call. Executes the command using one of exec() family of system calls.

Displays the prompt again, once the command is complete, or immediately displays the prompt if it is a background job.

Overview of Shell
A shell also provides a programming environment through a combination of :
standard Unix utilities and commands built-in shell commands

The programs written to work in environment of a shell are called shell scripts. A shell script is a text file containing above commands.

Overview of Unix - Process


A process is a program in execution. It is created by Unix to run a program. Each process in Unix is allocated a time slice. When a process consumes the time slice, Unix stops the process and resumes another process. In order to ensure that a process can be stopped and restarted as and when required, Unix stores a number of attributes for every process. Process id (pid), Parent Process Id (ppid) Todo: Find the pid and ppid of your shell process

Solaris Commands
The shell acts as a command interpreter in the following way:
The shell displays a shell prompt and waits for you to enter a command.
You enter a command, the shell analyzes it, and locates the requested program. The shell asks the system to run the program, or it returns an error message. When the program completes execution, control returns to the shell, which again displays the prompt.

Solaris Commands
file <filename> Kinds of files : text, binary, device man passwd to change your password Attributes of your Account:
Home Directory Pathname Login Shell Pathname User ID Group ID

cat /etc/passwd

Solaris Commands
When you log into Unix, your login shell also executes a startup script for you from your home directory. The name of this script depends upon the login shell. For Bourne shell, this file is .profile file. For C-shell, this file is .cshrc file. For bash, it is .bashrc To customize your login environment, you can modify these startup scripts. Todo: Add /usr/ccs/bin, /usr/local/bin to your PATH

Solaris Commands manipulating files & directories


In Unix, each file is a series of bytes without any structure (format). The directory is the only file that has a structure imposed on it. Each file has one or more names. Each file is also stored in a directory. The directories are stored in the file system. A file system is the useful arrangement of files into directories.

Solaris Commands listing files/dirs


In Unix, each file has a number of attributes associated with it. Some of these are:
File type File permissions File owner user ID and group ID

File size
Date/time of creation, last update and last access Number of hard links

Solaris Commands file names


A file name can contain any character except the following because these have special meaning to the shell:
Slash ( / ) Backslash ( \ ) Ampersand ( & ) Left- and right-angle brackets (< and >)

Question mark ( ? )
Dollar sign ( $ ) Left bracket ( [ ) Asterisk ( * ) Tilde ( ~ ) Vertical bar or pipe symbol ( | )

Solaris Commands file names


You may use a period or dot ( . ) in the middle of a file name. If you use a dot at the beginning of the file name it will be hidden when doing a simple listing of files thru the ls command. The maximum length of a file name depends upon the file system used. Most new file system allow a maximum length of 255 characters (the default). Older file systems allow a maximum file name length of only 14 characters.

Solaris Commands
The directory in which you are working at any given time is your current, or working directory. If you are uncertain about the directory in which you are working, enter the pwd (print working directory) command.
Todo: pwd

You can use the cd command to move to your home directory from any location. Todo: cd / pwd cd pwd

Solaris Commands pathnames


A pathname specifies the location of a directory or a file within the file system. A pathname consists of a series of directory names separated by slashes ( / ) that ends with a directory name or a file name. A pathname that starts with a slash ( / ) is called a full pathname or an absolute pathname.

Solaris Commands - pathnames


You can also think of a full pathname as the complete name of a file or a directory. Regardless of where you are working in the file system, you can always find a file or a directory by specifying its full pathname. The file system also lets you use relative pathnames. Relative pathnames do not begin with the / that represents the root directory because they are relative to the current directory.

Solaris Commands - pathnames


You can specify a relative pathname in one of several ways:
As the name of a file in the current directory.
As a pathname that begins with the name of a directory one level below your current directory. As a pathname that begins with .. (dot dot, the relative pathname for the parent directory). As a pathname that begins with . (dot, which refers to the current directory). This relative pathname notation is useful when you want to run your own version of an operating system command in the current directory (for example ./ls).

Solaris Commands - directories


In Unix, a directory is a file that has a number of entries. Each entry contains:
A filename The I-node number of the file

Every directory contains at least two entries:


Filename of .. (dot dot) Filename of. (dot)

Solaris Commands - directories


In the C shell and the Korn or POSIX shell, you may also use a tilde ( ~) at the beginning of relative pathnames. The tilde character used alone specifies your home directory. The tilde character followed by a user name specifies the home directory of that user. For example,
$ cd ~/mydir $ cd ~micky/mouse

Solaris Commands listing files/dirs


You can use the ls command to list files. The syntax of this command is:

ls [options] [directory_names]
Some of the options are:
-a, for all file names

-d, to list only directory names


-l, for a long (detailed) listing -R, for a recursive listing (traverse sub-directories) -t, for listing recently modified files

ls al

ls lrt (sorting by timestamp)

Solaris - listing files and directories


Examples: $ $ ls -l total 4 [1] -rw-r--r--rw-r--r--rw-r--r--rw-r--r-drwxr-xr-x
1. 2. 3. 4. 5. 6. 7.

[2] larry larry larry larry larry

[3] system system system system system

[4]

[5]

[6]

[7]

1 1 1 1 2

101 Jun 5 10:03 file1 75 Jun 5 10:03 file2 75 Jun 5 10:03 file2 65 Jun 5 10:06 file3 32 Jun 5 10:07 project

Number of 512-byte blocks used by files in this directory. Number hard of links to each file. User name of the file's owner. Group to which the file belongs. Number of bytes in the file. Date and time the file was created or last modified. Name of the file or directory.

Solaris - listing files and directories


Examples: $ ls -l total 2 -rw-r--r-- 1 larry system 101 Jun 5 10:03 file1 drwxr-xr-x 2 larry system 32 Jun 5 10:07 project $

The drwxr-xr-x indicates file type and permissions for each file. More about these permissions later

Solaris listing files/dirs


Following are some of the file types:
- (hyphen)
b c d l p s

for ordinary files


for block-special files for character-special files for directories for symbolic links for pipe-special files (first in, first out) for local sockets

Solaris type of file


Use the file command to see what kind of data a file contains. The file command displays whether the file is one of the following:
A text file A directory A FIFO (pipe) special file

A block special file


A character special file Source code for the C or FORTRAN languages An executable (binary) file

An archive file in ar format

Solaris file command


An archive file in extended cpio or extended tar format An archive file in zip format

A compressed data file in gzip format


A file of commands text (shell script) An audio file in .voc, .iff, or .wav format An image file in TIFF, GIF, MPEG, or JPEG format

This command is especially useful when you suspect that a file contains a compiled program, audio data, or image data. Displaying the contents of these types of files can produce strange results on your screen.

Solaris - Creating/Deleting Directories

You can use the mkdir command to create directory or sub-directories.


Examples: $ mkdir c_progs $ mkdir c_progs/shared

You can use rmdir command to delete a directory. The directory must be empty. You can also use the rm command with r (recursive) option.
Examples: $ rmdir c_progs $ rmdir c_progs/shared

Summary
ls ls a mkdir cd directory list files and directories list all files and directories make a directory change to named directory

cd
cd ~ cd .. pwd

change to home-directory
change to home-directory change to parent directory display the path of the current directory

Exercise 1a
Use the commands ls, pwd and cd to explore the file system. (Remember, if you get lost, type cd by itself to return to your home-directory)

Solaris - viewing files


You can use the cat command to view a file on screen.
Examples: $ $ cat test.c $ cat *.c

You can also use the cat command to create a file.


Examples: $ cat >> file1 This is line 1. This is line 2. ^D $

Solaris viewing files


Following commands can also be used to display a file :
pg
more vi (later)

The pg command lets you view one or more files. When you display files that contain more lines than will fit on the screen, the pg command pauses as it displays each screen.

Solaris - Copying files and directories


The cp (copy) command copies a file from one name to another name in your current directory or copies the file from one directory to another directory.
Examples: $ $ cp file2 file2x $ $ mkdir reports $ cp file2 reports

Solaris - renaming/deleting Files


You can use the mv command to rename or move a file.
Examples: $ $ mv test.c newtest.c $ mv test.c c_progs $ mv test.c c_progs/newtest.c

You can use the rm command to delete a file.


Examples: $ $ rm test.c $ rm c_progs/*.c $ rm c_progs/newtest.c

Summary
cp file1 file2 mv file1 file2 rm file copy file1 and call it file2 move or rename file1 to file2 remove a file

rmdir directory
cat file more file

remove a directory
display a file display a file a page at a time

head file
grep 'keyword' file wc file tail file

display the first few lines of a file


search a file for keywords count number of lines/words/characters in file display the last few lines of a file

Solaris I/O redirection


For every program, Unix automatically opens three files. These files are:
Standard input (file descriptor 0) Standard output (file descriptor 1) Standard error (file descriptor 2) < > or 1> 2>

Normally, the standard output and standard error file refer to the monitor whereas the standard input file refers to the keyboard.

Solaris - I/O Redirection

By using the I/O redirection facility, you can redirect output and error messages to a file. You can also take the input from a file. To redirect standard output, you can use the > symbol.
Examples: $ $ ls -Rl / > allfiles $ cat test.c > copytest.c

Solaris - I/O Redirection

To append standard output to an existing file, use >> symbol.


Examples: $ $ ls l *.c >> file_list Note: The file will be created if it does not exist.

To redirect standard error, use 2> symbol.


Examples: $ $ cat test.c junk.c 2> errors Note: Assumes that file junk.c does not exist.

Solaris - I/O Redirection

To redirect standard input from an existing file, you can use the < symbol. In general, any command that expects input from the keyboard can take the redirected input from a file.
Examples: $ $ cat < file_list $ mail s this is a file user1 < my_message

Solaris - Piping

The piping facility allows you to send the standard output from one program as input to another program.
Examples: $ $ ls l | wc l $ who | wc l $ ls l test.c junk.c | wc l

(output of ls is sent to wc) (output of who is sent to wc) (only output of ls is sent to wc)

Note: The last example assumes that file junk.c does not exist.

Summary
command > file command >> file command < file command1 | command2 redirect standard output to a file append standard output to a file redirect standard input from a file pipe the output of command1 to the input of command2 concatenate file1 and file2 to file0 sort data

cat file1 file2 > file0 Sort

Who

list users currently logged in

Solaris - Using the vi editor

Start the vi program by entering following command:


Examples:

$ vi file1 [Return]
~ ~ ~ ~ ~ ~ "file1" [New file]

This is a new file, so the system responds by putting your cursor at the top of a screen.

Using the vi editor

Type the lowercase letter i to specify that you want to insert text to the new file. The system does not display the i that you enter. Enter following text, pressing Return key after each line:
You start the vi program by entering [Return] the vi command optionally followed by the name [Return] of a new or existing file.

[Escape]

Using the vi editor

Press the Escape key to indicate that you have finished your current work. Type a colon (:) to enter the Last Line mode. The cursor will be placed on the last line of the screen, where you can enter the commands recognized by the vi editor. Enter lowercase letter w next. This indicates to the system that you want to write, or save, a copy of the new file in your current directory.

Using vi editor

Use dd command to delete current line. Use <n>dd command to delete <n> lines beginning from the current line. Use dw command to delete current word. Use <n>dw command to delete <n> words beginning from the current word.

Using vi editor

Use ^ command to move to beginning of current line. Use $ command to move to beginning of current line.

Use w command to move forward by word.


Use b command to move back by word.

Use e command to move to end of word.

Using vi editor

Use Ctrl-F command to move to next screen.

Use Ctrl-D command to move forward by half a screen.


Use Ctrl-B command to move to previous screen. Position cursor to any opening bracket and press % key to see the matching closing bracket. Press A command to add data to end of current line.

Using vi editor

Use yy command to copy current line. Use <n>yy command to copy <n> lines from the current line. Use p to paste the lines cut using the yy or the dd command. The lines are pasted AFTER the current line. Use P to paste the lines cut using the yy or the dd command. The lines are pasted BEFORE the current line.

Using vi editor

Use . command to repeat the last add, update, delete or paste command. Use x command to delete current character. Use <n>x command to delete <n> characters beginning from the current character. Use r<char> command to replace current character with <char> character.

Using vi editor

Use cw command to change current word with new word(s). Enter new words and press ESC when done. Use <n>cw command to change <n> words beginning with current word with new word(s). Enter new words and press ESC when done. Use C command to replace remainder of the line. Enter new text and press ESC when done. Use G to move to end of file.

Using vi editor

Use :/string command to search the string. Use n command to repeat the previous search.

Use :s/old_string/new_string command to substitute old_string with new_string in the current line.
Use :<m>,<n>s/old_string/new_string command to substitute old_string with new_string in line m thru n.For first line set m to 1. For last line, set n to $.

Using vi editor

Use :set nu command to see line numbers. Use :set nonu command to remove line numbers.

Use :set ai to enable auto-indent feature.


Use :set noai to remove auto-indent feature.

Use :set sm (show match) to enable bracket-match feature.

Quitting the vi editor

To save your work and quit:


Press the Escape key to indicate that you have finished your current work.

Type a colon (:) to enter the Last Line mode. Enter command wq.
This indicates to the system that you want to write, or save, a copy of the new file in your current directory and quit the vi editor.

Quitting the vi editor

To quit without saving your work :


Press the Escape key to indicate that you have finished your current work.

Type a colon (:) to enter the Last Line mode. Enter command q!.

This indicates to the system that you want quit the vi editor WITHOUT saving the changes you made to the file SINCE THE LAST w command.

Matching filenames

If the file names have a common pattern, the shell can match that pattern, generate a list of those names, and automatically pass them to the command as arguments. The asterisk (*), sometimes referred to as a wildcard , matches any string of characters.
Examples:

$ ls file *

Matching filenames

If the file names have a common pattern, the shell can match that pattern, generate a list of those names, and automatically pass them to the command as arguments. The asterisk (*), sometimes referred to as a wildcard , matches any string of characters. For example, file* will match any filename starting with word file.

Matching filenames

There is one exception to the general rules for pattern matching. When the first character of a file name is a period, you must match the period explicitly. For example, ls * displays the names of all files in the current directory except those that begin with a period. The command ls -a displays all file names, including those that begin with a period.

Matching filenames

This restriction prevents the shell from automatically matching the relative directory names. These are . (for the current directory) and .. (for the parent directory). In addition to the asterisk (*), shells provide other ways to match character patterns. These are summarized in the next slide.

Matching filenames

The filename pattern-matching characters are:


* ? [] [.-.] [!] matches any string, including NULL matches any single character matches any of the set characters matches any character within the specified range matches any character except those

in the set

Unix - Hard Links and Soft Links

There are two kinds of links available for your use:


hard links soft, or symbolic, links

When you create a hard link, you are providing another name for the same file. Hard links let you link only files in the same file system. All the link names are on equal footing. It is incorrect to think of one file name as the real name, and another as only a link.

Hard Links and Soft Links

Soft links or symbolic links let you link both files and directories. In addition, you may link both files and directories across different file systems. A symbolic link is actually a distinct file that contains a pointer to another file or directory. This pointer is the pathname to the destination file or directory. Only the original file name is the real name of the file or directory. Unlike a hard link, a soft link is actually only a link.

Creating Links

To link a hard link, use the following command format:


ln <existing_pathname> <new_pathname>

If you want to link files and directories across file systems, you can create symbolic links. To create a symbolic link, add an -s flag to the above ln command and specify full pathnames of both files.

Understanding Links

Each file has a unique identification, called an I-node number. The I-node number refers to files data stored at a particular location - rather than to the file name. A directory entry is a link between an I-node number and a file name. This link enables you to link multiple file names to the same I-node number. To display I-node number of files, use ls with the -i flag.

Understanding Links

Hard links to a file carry the same I-node number. Since an Inode number represents a file within a particular file system, hard links cannot exist between file systems. However, the soft link is a new file with its own, new I-node number. Since the soft link refers to the original file by name, rather than by I-node number, they work across file systems.

Deleting Links
The rm (remove file) command does not always remove a file. Assume that a file has several hard links (and therefore more than one file name). In this case, the rm command removes the link between the file I-node number and that file name, but leaves the physical file intact. The rm command physically removes a file only after it has removed the last link between that file and its names.

Viewing File System Info


The df command to displays the disk partition that holds a particular directory. Examples show that directories /u1/info and /etc are in different file systems, but that /etc and /tmp are in the same file system:
$ df /u1/info

Filesystem
$ df /etc Filesystem /dev/rz3a 30686

512-blks used
163124

avail
14166 avail 8364 avail

capacity Mounted on
92% /u1

/dev/rz2c 196990

512-blks used 19252 512-blks used

capacity Mounted on 70% /

$ df /tmp
Filesystem capacity Mounted on /dev/rz3a 30686 19252 8364 70% / $

Understanding Unix Security

Every valid user is known to the system through a user account. When a user account is created, information about the user is added to the following two files:
/etc/passwd - This file contains individual user information for all users of the system.

/etc/group - This file contains group information for all groups on the system.

These files define who can use the system and each user's access rights.

The /etc/passwd file

The /etc/passwd file contains records that define login accounts and attributes for all system users. This file can be altered only by a user with super-user privileges. Each record in the /etc/passwd file defines a login account for an individual user. The fields are separated by colons. The format of an /etc/passwd file entry is as follows:
username:password:UID:GID:gecos:login_directory:login_shell

Fields in /etc/passwd entry

username - Your login name.

password - Your password stored in encrypted form.


UID - A unique number identifying you to the system. GID - A number identifying your default group. You can belong to one or more groups.

gecos - This field usually contains general information about you, stored in some installation specific format.
login_directory - Your current directory after logging in to the system.

login_shell - The program run by the login program after you successfully log in to the system.

The /etc/group file

The /etc/group file defines login accounts for all groups using the system. This file can be altered only by a user with superuser privileges. Each entry in this file defines the login account of one group. Groups provide a convenient way to share files among users who are working on the same project. The format of each entry is :
groupname:password:GID:user1[,user2,...,userN ]

Format of /etc/group file entry

groupname

A unique character string that identifies the group to the system.


password This field is always empty. Entries in this field are ignored. GID (Group ID) A unique number that identifies the group to the system. usernames A list of users who belong to the group.

Protecting Files & Directories

Unix has a number of commands that enable you to control access to your files and directories. You can protect a file or directory by setting or changing its permissions, which are codes that determine the way in which anyone working on your system can use the stored data.

Protecting Files & Directories

Each file and directory has nine permissions associated with it, from following three types :
r (read) w (write) x (execute)

Above three permissions occur for each of the following three classes of users:
u (file owner)

g (group members of file owner)


o (all others; also known as world)

Protecting Files & Directories

The r permission lets users view or print the file. The w permission lets users write to (modify) the file. The x permission lets users execute (run) the file or search directories.

The user/owner of a file or directory is generally the person who created it. If you are the owner of a file, you can change the file permissions with the chmod command.

Protecting Files & Directories

The r permission for a directory means that its contents can be read, but not searched. Usually r and x are used together. The w permission for a directory means that files can be created or deleted. The x permission for a directory means that it can be searched.

Protecting files and directories


Examples: $ ls -l total 2 -rw-r--r-- 1 larry system 101 Jun 5 10:03 file1 drwxr-xr-x 2 larry system 32 Jun 5 10:07 project $

The drwxr-xr-x indicates file type and permissions for each file.
The first character indicates file type. The remaining characters are interpreted as three groups of three characters each that indicate what read (r), write (w), and execute (x) permissions are set for the owner, group, and others. If a hyphen (-) appears, the corresponding permission is not set.

Protecting files and directories

The entry drwxr-xr-x indicates the following:


This is a directory (the d letter) The owner can view it, write in it, and search it (the rwx sequence) The group can view it and search it, but not write in it (the first r-x sequence) All others can view it and search it, but not write in it (the second r-x sequence)

Default File Permissions

When you create a file or directory, the system automatically supplies a default permission. The following is a typical file permission :
-rw-r--r--

This permission specifies that the owner has read and write permissions while the group and all others have only read permission.

Default File Permissions

When you create a file or directory, the system automatically supplies a default permission. The following is typical directory permission :
drwxr-xr-x

This permission specifies that the owner has read and write permissions while the group and all others have read and execute (search) permission.

Default File Permissions

The default permission codes that your system provides relieve you from the task of specifying them explicitly every time you create a file or directory. If you want to create your own default permission codes, you must change your user mask with the umask command.

Changing File Permissions

Use the chmod (change mode) command to set or change the permissions for your files and directories. Please remember that whatever restrictions you impose, the superuser can always override them.

There are two ways to specify the permissions for chmod :


You can specify permissions with letters and symbols. You can specify permissions with octal numbers.

Changing Permissions Using Letters

The following is the format of the chmod command when using letters and symbols:
chmod userclass-operation-permission filename

The userclass-operation-permission entry represents three codes that specify the user class code, operation, and permission code that you want to activate. The filename entry is the name of the file or files whose permissions you want to change.

Changing Permissions Using Letters

Use one or more of the following to define a user class:


u g o a User (owner) Group All others (besides owner and group) All (user, group, and all others)

Changing Permissions Using Letters

Use one or more of the following to define an operation:


+ = Add permission Remove permission Assign permission regardless of previous setting

Changing Permissions Using Letters

Use one or more of the following to define a permission:


r s w x Read Set user or group ID Write Execute

Changing Permissions Using Letters


Assume a file file1 that has -rw-r--r set of permissions. Now, enter the chmod command with the flags go+w. This command expands the permissions for both the group (g) and for others (o) by giving them write access (+w) to file1 in addition to the read access they already have.

Changing Permissions Using Octals

You can also use octal numbers to change permissions. To use octal permission codes with the chmod command, enter the command in the following form:
chmod octal-number filename

The octal-number entry is a 3-digit octal number that specifies the permissions for owner, group, and others. The filename entry is the name of the file whose permissions you want to change.

Changing Permissions Using Octals

An octal number corresponds to each type of permission:


4 = read 2 = write 1 = execute

To specify a group of permissions, add together the appropriate octal numbers :


3 = -wx (2 + 1) 6 = rw- (4 + 2)

7 = rwx (4 + 2 + 1)
0 = --- (no permissions)

Setting Default Permissions

Every time you create a file or a directory, default permissions are established for it. These default permissions are initially established either by the operating system or the program you are running. The operating system assigns the default permission values of 777 for executable files and 666 for all other files.

Setting Default Permissions

If you want to further restrict the permissions established by a program when it creates a file or directory, you must specify a user mask with the umask command. The user mask is a value that determines the access permissions when a file or directory is created.

Setting Default Permissions

The umask command has following format:


umask octal-number

The octal-number is a 3-digit octal number that specifies the permissions to be subtracted from default permissions (777 or 666). Please note that through umask you actually specify permissions that are not to be granted.

Becoming another user

The su command lets you alter your identity during a login session. A reason for altering your identity is to be able to access files that you do not own. To protect system security, you should not assume another identity without the owner's or the system administrator's permission.

Becoming another user

The su command lets you log in to another user's account only if you know that user's password. The su command authenticates you and then resets both the process's user ID and the effective user ID to the value of the newly specified user ID. The effective user ID is the user ID currently in effect for the process

Becoming another user

The format of the su command is:


su username

The username entry is the user name whose identity you want to assume. To confirm what identity you have assumed, use the whoami command. This command displays the user name of the identity you have assumed.

Becoming another user

After completing your work under a new identity, you should return to your own login identity. To do so, press Ctrl/D or enter the exit command.

The super-user concept

Every Unix system has a super-user who has permissions that supersede those of ordinary users. This super-user is often referred to as root. The root user has absolute power over the running of the system. This user has access to all files and all devices and can make any changes to the system. The root user is said to have super-user privileges.

The super-user concept

The following is a list of tasks ordinarily performed by root users:


Edit files not usually changeable by ordinary users (for example, /etc/passwd) Change ownership and permissions of all files Execute restricted commands like mount or reboot Kill any process running on your system Add and remove user accounts Boot and shut down the system Back up the system Think properly before doing any of the above

The super-user concept

To become a root user, use the su command. You must know the password for the root user. The format is: su

The following example shows to become a root user :


$ su Password: ... #

The # prompt typically indicates the root user.

Changing owners and groups

In addition to setting permissions, you can control how a file or directory is used by changing its owner or group. Use the chown command to change the owner of a file. Enter the command in the following form:
chown owner filename

Changing owners and groups

Use the chgrp command to change the group of a file. Enter the command in the following form:
chgrp group filename

To change the group ownership of a file, you must be a member of the group to which you are changing the file.

Using Processes

A program is a set of instructions that a computer can interpret and run. While a program is running, it is called a process. Unix assigns a process identifier (PID) to every process. When a process begins executing, Unix opens three files for the process: stdin (standard input), stdout (standard output), and stderr (standard error).

Using Processes

Unix allows you to run a number of different processes at the same time. These different processes can be from one or multiple users. Therefore, you do not have to enter commands one at a time at the shell prompt. Instead, you can run both foreground and background jobs simultaneously.

Using Processes

Usually, when you enter a command on the command line, you wait for the results to display on your screen. Such commands are called foreground processes or jobs. However, some commands require long time. If a longduration command runs as a foreground job, you cannot execute other commands until the current one finishes. As a result, you may want to run such command as a background job.

Using Background Jobs

To run a background job, you end the command with an ampersand (&). Once a job is running in the background, you can perform additional tasks by entering other commands at your workstation.

Using Background Jobs

After you create a background process, the following takes place:


The PID is displayed. In the Korn and POSIX shells or the C shell, job numbers are assigned as well.

The prompt returns so that you can enter another command.


In the C shell, a message is displayed when the background process is complete.

Unix Operating System

Multi User

Multi Tasking

Multi Processing

Time Sharing

Multi User
More than one user can access the system
user1 UNIX OS user3 user2

Multi Processing
Number of processes can run at a time.
Example: you can write Scripts, Functions and also you can do a print job in the background, Browse the net.,etc
Back

Multi Tasking
A technique used in an operating system for sharing a
single processor between several independent jobs.
Cooperative multitasking" the running task decides when to give up the CPU . Pre-emptive multitasking" (probably more common) a system process called the "scheduler" suspends the currently running task after it has run for a fixed period known as a "time-slice".

In both cases the scheduler is responsible for selecting the next task to run and (re)starting it.
Back

Time Sharing
An operating system feature allowing several users to run several tasks concurrently on one processor, or in parallel on many processors, usually providing each user with his own terminal for input and output

Back

Unix Architecture
Utility, command or shell script shell
User Mode Kernel Mode

system calls
File System
Kernel

I/O System

Memory Manager

Scheduler

Buffer Cache

Interrupt and Exception Handlers

The kernel
The kernel is the core of the UNIX operating system. Basically, the kernel is a large program that is loaded into memory when the machine is turned on, and it controls the allocation of hardware resources from that point forward. The kernel knows what hardware resources are available (like the processor(s), the onboard memory, the disk drives, network interfaces, etc.), and it has the necessary programs to talk to all the devices connected to it.

Shell
Is an interface between the user and the OS Kernel.
Types of Shells : Korn, C, Bourne, Bash, tcsh, etc.

Pictorial Representation of System Architecture


user
I/O Redirection

kernel
Hardware

shell
Application

Unix Kernel

S-ar putea să vă placă și