Solaris/Unix Training
Solaris/Unix Training
Solaris/Unix Training
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
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
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
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.
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
File size
Date/time of creation, last update and last access Number of hard links
Question mark ( ? )
Dollar sign ( $ ) Left bracket ( [ ) Asterisk ( * ) Tilde ( ~ ) Vertical bar or pipe symbol ( | )
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
ls [options] [directory_names]
Some of the options are:
-a, for all file names
ls al
[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.
The drwxr-xr-x indicates file type and permissions for each file. More about these permissions later
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.
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)
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.
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
Normally, the standard output and standard error file refer to the monitor whereas the standard input file refers to the keyboard.
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
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
Who
$ 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.
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]
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.
Using vi editor
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.
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.
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
in the set
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.
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
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.
Filesystem
$ df /etc Filesystem /dev/rz3a 30686
512-blks used
163124
avail
14166 avail 8364 avail
capacity Mounted on
92% /u1
/dev/rz2c 196990
$ df /tmp
Filesystem capacity Mounted on /dev/rz3a 30686 19252 8364 70% / $
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 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
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 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 ]
groupname
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.
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)
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.
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.
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.
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.
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.
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.
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.
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.
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.
7 = rwx (4 + 2 + 1)
0 = --- (no 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.
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.
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.
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.
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
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.
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.
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.
To become a root user, use the su command. You must know the password for the root user. The format is: su
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
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.
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.
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
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.
kernel
Hardware
shell
Application
Unix Kernel