Académique Documents
Professionnel Documents
Culture Documents
1. 2. 3. 4. 5. 6.
sh: THE COMMAND (chap 7) MECHANISM OF PROCESS CREATION FEATURES OF UNIX UNIX ARCHITECTURE. UNIX FILE SYSTEM
By DHAVAL DALSANIA
All files in UNIX are related to one another. The file system un UNIX is a collection of all these related files (ordinary, directory and device files) organized in a hierarchical (an inverted tree) structure. This system has also been adopted by DOS and Windows, and is visually represented in Figure. root (/)d
bin
dev
etc
home
mnt
stand
tmp
usr
dsk
rdsk
henry
unix
bin
kumar
sharma F0ql18dt safe The UNIX file system The implicit feature in every UNIX file system is that there is a supremo, which serves as the reference point for all files. This top is called root, and is represented by a /(frontslash). root is actually a directory file, and it has a number of sub-directories under it. These sub-directories, in turn, have ore sub-directories and other files under them. For instance, bin and usr are two directories directly under root, while a second bin and kumar are sub-directories under usr. Every file, apart from root, must have a parent, and it should be possible to trace the ultimate parentage of a file to root. If the ancestry of a file cant be traced to root, the file is simply not part of the file system. This should be easy for you to understand as we all have our own families with similar grandparent-parent-child relationships. Thus, the usr directory is the parent of kumar, while root is the parent of usr, and the grandparent of kumar. If you create a file login.sql under the kumar directory, then kumar will be the parent of this file. It is also obvious that, in these parent-child relationships, the parent is always a directory. usr and kumar are both directories as they are both parents of at least one file or directory. login.sql is simply an ordinary file; it cant have any directory under it. By DHAVAL DALSANIA 0s0 login.sql progs
The shell, normally, cant do any work while the command is being executed. It has to wait, and when execution is complete, it return the $ prompt for resuming the next cycle.
Q - FEATURES OF UNIX.
Multitasking capacity Multiuser capacity Communication Security Portability Pattern matching Programming facility System call & libraries Windowing system Documentation 1) Multi-user Capacity: The resources are shared between all users, like CPU, RAM, H/W, etc. for this purpose, the computer break up a unit of time into several segments and each; user is allow allocated a segment. So, at a time, the machine will be doing the job of a single user when first job gets completed, the next job gets started. The process goes ;on till the clock has turned full-circle. And first users job is taken once again. By DHAVAL DALSANIA
Whole process is done by kernel. There are several types of terminal used with network. 1. Dumb terminals:- it is having only keyboard and a display unit. It does not contain memory or disk of its own. 2. Terminal emulsion: - A terminal is having its own microprocessor, hard disk, and memory. By attaching it to host we can emulate it to work as dumb terminal. At that time, the terminal can not use its own memory. There are s/w like VTERM & XTALK used as a terminal emulsion s/w. 3. Dial-in terminals: - The terminal is connected to host through telephone line. For the dial-up we need modem.
C C
2) Multitasking Capacity: It is capable of carrying out more than one job at the same time,. So it is called multitasking. We can switch jobs between background and foreground. One job is running normally while other as a background. CPU manages this facility intelligently. Depending upon the priority of jobs, the O.S. allots small time slots to each foreground & background process. The DOS is also a multitasking of but when one job is executing, it would stops other job to execute. So it is not truly multitasking. In multitasking, scheduling is very important. 3) Communication: It provides communication between two users of same hardware or inter-network. The user can easily change data, programs, and mail through such facility. 4) Security: UNIX has three inherent provisions for protecting data. By assigning passwords and login names to each individual users. At file level there are read write, execute permissions, which decide who can read it, modify it or execute it. The third option is file encryption. It encodes your file into an unreadable format, so that even if anybody succeeds in opening it, secretes are sage. When we want to access data, we can decrypt it. 5) Portability: It can be adapted to any computer system, because it is designed in C language. 6) Pattern matching: By DHAVAL DALSANIA
The * is not only one character used as a pattern matching. But there are so many others. The pattern-matching does not only associate with file names. Some tolls also use a special expression called regular expression that is framed with characters from this set. When you use a single expression to match a number of similar patterns, you can watch tem in one shot. 7) Programming facility: It is highly programmable. The UNIX shell programming language has all the necessary tools like control structures, loops & variables. 8) System call & libraries: As it is created in C, there are so many library functions which are be used with system calls The calls are made by kernel. Interaction through system calls represents an efficient means of communication with the system. 9) Windowing systems: It provides an environment that allows multiple windows where for each application-each window. X windows also support networked application. Where process is done on one machine, while output is on another. 10) Documentation: For each utility of UNIX there are documents available.
Q - UNIX ARCHITECTURE.
The functionality of UNIX can be divided into 3 levels. User & application program: User interacts with applications of UNIX and uses the different utilities of the task. These applications speak our language to system. Shell: Communication between user and kernel can be done by a middleware, called shell. It is an interpreter (a mediator) that interprets the command that we give. Then it conveys them to kernel, which ultimately executes them. If we say kernel is monarch (ruler) then the shell is emissary (representative). Shell is also called sleeping beauty of UNIX. The shell is agency which takes care of the features of redirection with the > & | symbols. It has its own programming ability. Kernel: It is the heart of UNIX system. It is a collection of program mostly written in C, that directly communicate4 with h/w. There is one kernel for every system, which is loaded into system, when the system is booted. It manages system resources, allocates time between users and processes, and decides process priorities & performs all other tasks that we would not like to bother about. By DHAVAL DALSANIA
The kernel isolates itself form the user programs and these programs are independent of h/w they use. It is easy to move them across different system so. it is often called operating system. Kernel programming is called UNIX whereas the shell program is in a file called sh. At a time there may be more than one shell but kernel only one. At any instance, UNIX is capable of executing only one program, so there is no need for more than one shell.
USER
SHELL
UNIX COMMANDS
SHELL
USER
HARDWARE
DATABASE PACKAGES
COMPILERS KERNEL
USER
USER
The root directory also contains a file called UNIX, which is UNIX kernel itself. These directories are known as sub-directories and content of these directories are called sub-sub-directories. /root(root directory)
unix
bin
lib
dev
usr
tmp
etc
(Sub directory)
user1 user2
usern
(Sub Directories)
(Basic Structure of UNIX file system) The main reason behind creation of directories is to keep related files together and separate them form other group of related files. Dev-All devices related files stored in Dev directory. Tmp-All temporary files are stored in tmp directory. Bin-Bin directory contains executable commands and files. UNIX commands may be either C programs or shell programs. Shell programs are collection of several UNIX command. Lib-It stores library functions provided for programmers. The programs written under UNIX make use of these library functions in lib directory. Dev-Thee dev directory contains files that control various input /output devices like terminal, printers, disk devices. For each device there is a separate file. In UNIX each device is treated as file. For example, everything that is displayed on terminal is first written to a file associated with terminal. Usr- All user directories contained in usr directory. In user directory there are several directories. Each associated with a particular user. The system administrator creates these directories when he creates accounts of different users. Tmp-The tmp directory contains the temporary files created by UNIX or by users. These files get automatically deleted when the system is restarted.
Contains Library functions Device related files Binary executed files usually required for system administration Temporary files created by UNIX or users Home directories of all users Additional binary executable files
Features of UNIX file system: It has a hierarchical file structure. Files can grow dynamically. By DHAVAL DALSANIA
By DHAVAL DALSANIA
It is an important default security feature provided by UNIX to change file permission by owner only. It is used to set three permissions for all three categories of users (owner, group, others). It takes as its argument an expression, which combines the category, the operation and the type of permission. Syntax: chmod <category> <operation> <permission> <filename(s)> By DHAVAL DALSANIA
Abbreviations used by chmod Category u user g -- group o others a all Operation + - assign permission - - remove permission = - assign absolute permission Permission r read permission w write permission x execute permission
E.g. r w r - - r - In above example execution permission is given to none of user. To assign execution permission to user, while other permission remains same $ chmod u+x <filename> $ chmod ugo+x <filename> $ chmod a+x <filename> $ chmod +x <filename> $ chmod a-r <filename> $ chmod ug-r <filename> $ chmod u-x,go+r <filename> but This indicates the user would have execute permission This indicates the user, group and others would have execute permission This indicates the user, group and others would have execute permission This indicates the user, group and others would have execute permission This indicates the user, group and others would not have read permission This indicates the user and group would not have read permission This indicates the user would not have execution permission, group and others has read permission on the same file. It is a combination of different permission on a single file.
Absolute assignment It can be done by using = operator. It assigns only those permissions that are specified along with it, and remove other permissions. $ chmod u-w, o-wx <filename> $ chmod ugo=r <filename> $ chmod a=r <filename> $ chmod =r <filename> or or or
Octal notation There is a short hand notation available for changing the file permissions. The command uses a numeric argument that describes both the category, as well as the permission. The notations are as bellow: Read permission 4 Write permission 2 Execute permission 1 e.g. $ chmod 421 <filename> It says that the owner has read permission, the group has write permission, the others has execute permission $ chmod 777 <filename> It says that all has all permission. Because 4+2+1 = 6 so 6 means read and write permissions $ chmod 666 <filename> Only read and write permissions to all $ chmod 000 <filename> No permission to any one. By DHAVAL DALSANIA
Directory Permissions The permissions of directory differ from the file permissions. It is possible that a file cant be read even though it has read permission, and can be removed even when it is write-protected. It shows that permission of directory also affects the permissions of files.
(16.7)
It requires an expression to represent the pattern to be searched from file. It is generally safe to quote the pattern. It is necessary if the search string consists of more than one word or uses any of the shells character like *. E.g. $ grep pattern <filename>
Options Descriptions $ grep c pattern <filenames> counts no of occurrence of pattern inside the filename $ grep n pattern <filenames> the line no are shown where the pattern is found $ grep v pattern <filenames> it selects all but the lines containing the pattern $ grep l pattern <filenames> it displays only the name of files where a pattern has been found $ grep i pattern <filenames> it ignores case $ grep e pattern1 e pattern2 <filenames> it allows to match more than one pattern $ grep A <no> pattern <filenames> it allows to match no of lines after specified <no> $ grep B <no> pattern <filenames> it allows to match no of lines before specified <no> $ grep N <no> pattern <filenames> it controls the number of occurrences. So -N2 would list two occurrence The basic expression Character Sub-set 1) Asterisk operator: GGG It refers to immediately preceding character. G*
6) [^pqr]:
By DHAVAL DALSANIA
CHAP 13 PROCESSES
Q kill
COMMAND
The system often requires communicating the occurrence of an event to a process. This is done by sending a signal to the process. When the process receives a signal, it may ignore it, terminate or do something else. If user has a program running longer than the accepted, user can sends signal to active process with a specific request of termination. It can be done either by interrupt key or by kill command. It takes PID as its arguments, and terminates the process with that PID. Syntax: $ kill <PID> E.g.: $ kill 512 98 45 67 The & operator will show the PID of the process that is run in the background. If user can run more than one job in the background, they can all be killed with a single kill command and by specifying all PIDs. If all these processes has same parent process, then killing of parent process would directly kill the child processes. User can not kill init process. The system variable $! stores the PID of the last background job. When user run more than one job in the background, this parameter stores the PID of only the last one. The $$ variable stores the PID of last process E.g. $ kill $! Killing with Signal Numbers: The kill command uses the signal number 15 to terminate the process, by default. Sometimes a program may ignore the interrupt, and still executing the command. In this case, the process can be killed with signal no. 9. E.g. $ kill -9 121 It kills process 121 with signal no. 9 $ kill 0 The 0 signal will kill all processes in system except the login shell. $ kill -9 $$ Kills current shell $ kill -9 0 kill all processes including the login shell $ kill -1 0 kill all processes including the login shell
Q nice COMMAND
In UNIX environment, all jobs are executed with equal priority. This is not always desirable, because high-priority jobs must be completed at the earliest. The nice command reduces the priority of jobs. It is used with the & operator. More important jobs can then have greater access to the system resources.
Q at COMMAND
UNIX provides very sophisticated facilities to schedule a job to be run at specified time of day, rather than now. It is also useful because the load on any system. It makes sense to schedule less urgent jobs at a time when the system overheads are low. The at command takes as its argument the time the job is to be executed. The input to the command has to come from the standard input E.g. $ at 12:30 abc.sh <Ctrl -d> It means that at 12:30 p.m. today the script abc.sh will be executes. The job number, the date and the time of scheduled execution are also shown. This job number is derived from the number of seconds that have elapsed (onwards) since 1970. The standard output and standard error of this shell script will be mailed to the user, who can then have a look at this mail. The output can be redirected to any file even $ at 12:30 abc.sh > abc.lst It also offers the key words now, noon, midnight, today and tomorrow, which can be used in scheduling commands. It accepts the + symbol to act as an operator. Another key words used are hours, days, weeks, months and years. By DHAVAL DALSANIA
$ at noon $ at now + 1 year $ 12:00 + 1 day $ 9 am Mon $ 9 am tomorrow The at queue is displayed with the l option. It shows, for each submitted job, its number, the schedule and date of executions, as well as day of week. But it does not provide the name of job. $ at l $ at r <job> it will removes the specified job
By DHAVAL DALSANIA
SHELL SCRIPTS
When a group of commands has to be executed regularly, they are stored in a file. All such files are called shell scripts, shell programs, shell procedures. There is no restriction for the file name extension, but .sh is used universally. We can use Vi editor or using cat command, we can create shell scripts. The # operator is used for command line arguments.
POSITIONAL PARAMETERS
Shell procedures accept arguments in another situation, when user specifies them in the command line itself. It is quite useful for scripts requiring few inputs. It also forms the basis of developing tools that can be used with redirection and pipelines. When arguments are specified with a shell procedure, they are assigned to some variables called positional parameters. The first argument is read by the shell into the parameter $1, the second as $2, and so on. User can use more positional parameters in this way up to $9. They are called shell variables because all variables are evaluated with a $ before the variable name. There are a few other special parameters used by the shell. $0 $* $# that $? $! $@ It contains the name of the program It stores the complete set of positional parameters as a single string. It is set to the number of arguments. It lets user to design scripts check whether the right number of arguments have been entered. It stores the exit status of the last command. It has the value 0 if the command succeeds, and a non-zero value if fails. PID of last background process same as $* except when enclosed in double quotes.
E.g. $ cat emp.sh >echo Program : $0 The number of arguments specified is $# The arguments are $* grep $1 D2 echo e \n Job over $ emp.sh director emp1.lst program : emp.sh The number of arguments specified is 2 The arguments are emp1.lst 1006 | jalpa rathod | director | sales | 03/09/03 | 6700 6521 | sunil makhaulia | director | purchaser | 03/09/03 | 7800 Job over
The shell provides two operators to control execution of a command depending on the success or failure of the previous command. These operators are && and ||. The && operator delimits two commands; the first command is executed only when the first succeeds. The || operator is used to execute the command when the previous command fails. $ grep director emp.lst && echo Pattern found This would give output Pattern found, if pattern founded in the file. $ grep director emp.lst || echo Pattern not found This would give output Pattern not found, if pattern does not founded in the file.
if
It takes two-way decision, depending on the fulfillment of a certain condition. It evaluates a condition that accompanies its command line. If the condition is fulfilled, the sequence of commands following it is executes. Every if must have a corresponding fi. Syntax: if <condition> Then <Execute commands> elif <condition> <Execute commands> else <Execute commands> fi E.g. $ if grep director emp.lst > then echo found > else echo not found > fi
test
When if is used to evaluate expressions, the test statement is also used to control command. It uses certain operators to evaluate the condition on its right, and returns either a true or false exit status. It is then used by if statement for decision making. It does not display any output but simply returns value. There are certain relational operators used with the test command. Operator Meaning -eq Equal to -ne Not equal to -gt Greater than -ge Greater than or equal to -lt Less than -le Less than or equal to E.g. $ cat emp3.sh if test $# -ne 3 then echo you have not keyed in 3 arguments exit 3 else if grep $1 2 > 3 then Echo Pattern found else Echo pattern not found fi fi
By DHAVAL DALSANIA
Short hand for test is widely used as rectangular brackets, and the expression can replace the word test. E.g. test $x eq $ $y [ $x eq $ $y ] STRING COMPARITION: The test can be use to compare two strings. Here = is used for equality and != is used for inequality. Test Description -n str True if string str is not null -z str True if string str is a null string s1 = s2 True if s1 = s2 s1 != s2 True if s1 != s2 str True if str is assigned and not null if [-n $pname a n $flanme]; then grep $pname $flname || echo Pattern not found else echo At least one input was a null string exit 1 fi FILE TEST: It can be used to test the various file attributes. E.g. user can test whether a file has the necessary read, write or executable permissions. E.g. Test -e file -f file -r file -w file -x file -d file -s file Description True if file exists True if file exists and is a regular file True if file exists and readable True if file exists and writable True if file exists and executable True if file exists and directory True if file exists and has a size greater than zero
case
It is the conditional offered by shell. It matches an expression for more than one alternative, and uses a compact construct to permit multi-way branching. It also handles string tests, but in more efficient manner than if. Syntax: case <expression> in pattern1 ) <execute commands> ;; pattern2 ) <execute commands> ;; pattern3 ) <execute commands> ;; esac It matches the expression first to pattern 1, if successful, then executes the commands associated with it. If it does not matches, then searches for pattern 2. Each command list is terminated by a pair of semi-colon, and finally with esac. E.g. $ cat menu.sh echo MENU\n 1) List of files\n 2) Processes of user\n 3) Users of system\n 4) Exit\n Enter your options : \c read choice case $choice in 1) ls l ;; 2) ps f ;; By DHAVAL DALSANIA
3) who ;; 4) exit esac It can not handle relational and file test. It can only match strings. It is also most effective when the string is fetched by command substitution. It is also possible to match more than one pattern. E.g. echo Do you wish to continue : \c read ans case $ans in y | Y) ;; n | N) exit ;; esac Like the shells wild-cards, it also uses filename matching metacharacter *, ? and the character class. E.g. echo Do you wish to continue : \c read ans case $ans in [yY] [eE] * ) ;; [nN] [oO] ) exit ;; esac
expr
The shell does not have any computing features at all; it has to rely on the expr command. It combines two functions in one; it can perform arithmetic operations on integers and also manipulate strings to a limited extent. It makes the shell relatively slow, but it can be useful in handling simple arithmetic tasks. It can perform basic four arithmetic operations. E.g. $ x=3 y=5 $ expr 3 + 5 8 $ expr $x - $y -2 $ expr $y / $x 1 $ expr $y % $x 3 The operand +,-,* etc., must be enclosed on either side by white space. To use multiplication operand (*), it has to be used with backspace (\). The most common use of expr is in incrementing the value of a variable. E.g. $ x=5 $ x = `expr $x +1` # it is same as x++ $ echo x
While
It repeatedly performs a set of instruction till the control command returns a true exit status. Syntax: while <condition> do <commands> done answer =y while [$answer = Y] do
E.g.
By DHAVAL DALSANIA
echo Enter the code and description : \c read code description echo $code | $description >> newlist echo Enter any more (Y/N)? \c read anymore case $ anymore in y*|Y*) answer=Y;; n*|N*) answer=N;; *) answer=y;; esac done Suppose the system administrator wants to see the free space available on disks every five minute, an infinite loop is needed. E.g. while true ; do df t sleep 300 done & At every 5 minutes, user will get information about the free space.
Until
It is the complement of while loop. It has sense that the loop body is executed repeatedly as long as the condition remains false.
For
It is different in structure from the ones used in other programming languages. There in no next statement in this for loop. Syntax: for <variable> in <list> do <execute commands> done The loop body is the same, but the additional parameters variable and list are used. The loop body is executed as many times as there are items in the list. E.g. $ for x in 1 2 3 4 > do > echo The value of x is $x > done The list can consist of any of the expressions that the shell understands and processesvariables, wild-cards, command substitutions and positional parameter. List from variables E.g. $ for var in $PATH $HOME $MAIL > do > echo $var > done List from wild-cards E.g. $ for file in *.c > do > cc -0 $file{x} $file > done List from positional parameters E.g. $ for pattern in $* > do By DHAVAL DALSANIA
> grep $patten emp.lst || echo Pattern $pattern not found > done List from command substitution E.g. $ for file in `cat clist` This is most suitable method. The basename command is used with the for loop to change the extension of group of files. E.g. $ basename / home / Sunil / project / abc.pl If it is used with the second arguments, it strips off the string from the first arguments. E.g. $ basename abc.txt txt abc. To rename filename extension txt to doc: E.g. $ for file in *.txt > do > leftname = `basename $file txt` > $file ${leftname}doc > done It is not shell built-in, but an external command.
set
Unlike shell variables, the positional parameters as well as the parameters associated with it can not be set by making a direct assignment with the = operator. User can put some values into positional parameters in an indirect manner using set command. E.g. $ set 111 222 333 So $1 = 111, $2 = 222 and $3 = 333.
This feature is particularly useful for picking up individual fields from the output of a program. E.g. $ set `date $ echo $* sat sep 13 21:12:29 IST 1997 $ echo The date of today is $2/$3, $6 the date of today is sep 13, 1997 shift It transfers the contents of positional parameters to its immediate lower numbered one. This goes on as many times as the statement is called. When called once $2 becomes $1, $3 becomes $2 and so on. E.g. $ set `date` $ echo $* sat sep 13 21:12:29 IST 1997 $ echo The date of today is $2/$3, $6 the date of today is sep 13, 1997 By DHAVAL DALSANIA
By DHAVAL DALSANIA
2) It runs on a TCP/IP network It works only if the recipients terminal is enabled (mesg is y) E.g. $ talk Sunil Second user has to use talk command to communicate with the first user. The advantage of talk over write is that user can easily differentiate between sent and received messages. The top window displays the sent messages, while the bottom windows show the received messages. It can be terminated by either user entering the interrupt key. mail I is used to mail any user. The advantage with these commands is that user need not handle mail the moment user is informed of it. But user can reply whenever he/she wishes. It is one of the most well-known commands in the UNIX repertoire (list) of electronic mail. Even though it has a host of options and internal commands, few of them are really complex. Syntax: $ mail < recipients name> Subject: <message> <ctrl + d> Cc: If the recipient is busy with another task, then this command would not interfere in the execution of that command. When another task gets completed, the recipient would get message of new mail. If any user wants to check the mail, he/she has to use command mail without any argument. It would list all the new mail received. It postmarked with the name of the sender, the date and time of sending it. There is no. of internal command that can be used with the & prompt when user is checking mailbox. It saves message in a mailbox, which normally is placed in the directory /var/spool/mail/username. But when the message is not saved but only viewed than it would be saved in the file $HOME/mbox automatically at the time of quitting from mailbox. Mail Internal Commands: Option Description + To check next mail To check previous mail <num> To check particular no. of message (E.g. 3 is used to check third mail) w <m no> < fname> User can save one or more messages in separate file rather that the default mailbox (mbox). E.g. w 123 note saves 1, 2, 3 no. of message in the file note s User can save mail message with all header an postmarks E.g. s 134 mailfile appends message no. 1, 3, 4 in to mailfile. d To delete file from the mailbox. It deletes the message when quitting from the mailbox u To undelete any delete marked mail. r It enables the recipient to reply when the sent message is on display at terminal. h Prints headers of all messages m <user> Forwards mail to another user q Quitting from mailbox. ! <command> runs UNIX command It is not user-friendly, which makes use of the program quite difficult for casual users. elm By DHAVAL DALSANIA
It is the mail handler generally shipped with most of Linux, not with UNIX. It is a menudriven, extremely simple to use and quite powerful. It feels up the entire screen when invoked by the command name. At the bottom of the screen options are given. The option menu is straight forward. To check any message, move the highlight up and down to select that the message and then press <enter>. Sending a mail is simple as reading the mail. Option Description -r to reply any mail -z to check whether there is any mail in mailbox q quit s send mail
pine the pine stands for Program for Internet News and E-mail. It is widely used on the internet. It was developed by the University of Washington. It combines simplicity and power using a core set of minimal functions. It can be used without using any manuals. The mailer can be called up simply by invoking pine. The menu items are neatly laid out. Apart from sending and receiving mail, user can also maintain the address book. It has context sensitive help that is invoked by using ? in most cases. Viewing Mail: The option i and l are used for the purpose of viewing the contents of the folders. A message can be selected using arrow key and then press <enter> key. If user has more messages to view, option n can used to see them in turn, while p is used to check previous one. Composing Mail: The option c is used to compose a message. pine has its own editor for composing. It also gives conformation at the time of saving message. The Address Book: It is an interesting feature of pine. Here user can enter a persons details just once so they ca be picked up from the book subsequently (later). From the address book itself user can compose message. It also allows spell checking. It also provides multimedia attachment. finger It is a versatile (flexible) command having communicative features. When used without any arguments, it simply produces a list of all logged users. If any user is specified with the finger command, it works like who. vacation It is sometimes necessary to leave behind your schedule and other important information for others to see. It is not simply possible to send mail to all users. The vacation command uses the mail forwarding facility, but its used only when the recipient is away on vacation. All incoming mail will now be saved, and the senders will be automatically sent the message to indicate that the recipient is away.
By DHAVAL DALSANIA
When a file is copied, both the original and copy occupy separate space in the disk. UNIX allows a file to have more than one name, and yet maintain a single copy in the disk. Changes to one file are also reflected in the other. The file is then said to have more one link, i.e., it has more than one name. a file can have as many names as user want to give it, but the only thing that is command to all of them is that they all have the same inode number. In win 95 and NT, the same principle is called shortcut. But these shortcuts itself contain some disk space. In UNIX, user can easily know the number of links of a file from the fourth column of the ls l listing. This number is normally 1 but exceed this figure for linked lists. The files can be linked using ln command, which takes two filenames as arguments. $ ln emp.lst employee
E.g
The i option shows that the links of file. All the linked files have same status; its not that one file contains the actual data and the others dont. The file has simple different aliases. So changes done in one file automatically available in the other files. A file is considered to be completely removed from the system when its link count drops to zero. Sometimes, it is difficult to remove all links to a file, especially when they exist in multiple directories. It is also called hard link. The UNIX system also features another form of link, the symbolic link. This link being more flexible is also known as a soft link. The hard link has two limitations. 1) User cant have two linked files in two file systems. 2) User cant link a directory even within the same file system The soft links points to the file which actually has the contents. The concept of shortcut in win- 95 is the soft link. The link can be created using s option with ls command.
By DHAVAL DALSANIA
SHUTDOWN PROCESS It usually performs following activities: 1) Notifies users with wall about the system going down and directive to log off. Users are then expecting to close all their files and log out of the system within a minute or so. The shutdown itself sleeps for a minute after mailing the first message and may issue a reminder or two. 2) Sends signals to all running processes so that they can terminate normally. 3) Logs users off and kills remaining processes 4) Unmounts all secondary file system, i.e., detaches them from the root file system. 5) Writes information about file system status to disk to preserve the integrity of the file system 6) Notifies users to reboot or switch off, or moves the system to single-user mode When the message appears on the screen, the machine can be considered to have completed the shutdown sequence successfully. The system can be switched off or rebooted. On most systems the shutdown is shell scripts, which is too often edited by administrator. It has to be run from the root user account, and in some installation, is invocable only from the console. It requires the knowledge of the root password, while booting into multi-user mode it does not required. There is also a reboot command that cuts short the normal shutdown procedure and reboots the system; users are not warned even. The command haltsys, which brings down the system instantly. Their use is not recommended on multi-user mode. Q MANAGING DISK SPACE This is really crucial task performed by administrator. Although a lot of disks are added to the system, it will be scramble (mix up) for space. Users often forget to remove the files they no longer required. There are a number of files, in the directories /tmp and /usr/tmp that tend to accumulate during the day. If his build-up is not checked, the entire disk space will eventually be full. So it would slowdown the system performance. So administrator has to monitor the space and remove that have outlived their utility. Sometimes some users may use more space than they are supposed to use. It can be achieved by command df and du. It can be issued by any user. Both of them report disk usage or the free space in terms of blocks, the unit of measurement is 512 bytes. 1) The df command It reports the amount of free space available on the disk. The output always reports for each file system separately. There are four file systems, of which the first tow is always created by system installation. The system will continue to function until the free blocks or inodes are eaten away, whichever occurs earlier. The total free space in the system is the sum of the free blocks of the four file system. 2) The du command Sometimes user wants to find out the consumption of a specific directory tree rather than an entire file system. The du command reports usage by a recursive examination of directory tree. By default, it lists the usage of each sub-directory of its argument, and finally produces a summary. 3) pack, compress, gzip and zip: file compression There will be always be a number of files that are required moderately, and which user wont like to back up an restore repeatedly. The pack and compress gives facility of compression utilities and release some disk space. The pack is quite inefficient in compression. The compress is quite fast and compress well. By DHAVAL DALSANIA
The uncompress command is used to produce back the original file. Q find COMMAND TO LOCATE ANY FILE Q BACK UP AN OVERVIEW The administrator is responsible for the safety of the data that resides in the system. It is the part of duties of administrator that the files should be backed up and determine the periodicity of such backups. The effectiveness of the backup is determined by your ability to restore lost or corrupted data files easily. User often accidentally deletes their own files and then wants to restore them. The administrator has to plan his backups carefully so that he doesnt back up the same file over and over again even though it has not bee accessed from a long time. Some files are modified more often than others, while some are not accesses at all for months. The classical theory for the backup is that there should be a complete backup of all files once a week, and a daily incremental backup of only those files which have been changed or modified. But the routine may be modified depending on the size and nature of installation. If administrator can make all the data fit into a single tape, he can leave the backup process unattended too so that he doesnt need to change tapes. The backup device can be magnetic or a cartridge tape, a floppy diskette, or even a disk file. The two most popular programs for backup are cpio and tar. Both combines a group of files into a single file, called archive file, with suitable headers preceding the contents of each file. The cpio command is often preferable to tar for many reasons describe as follow: 1) Since cpio can take its list from find, it can back up files selectively, while tar is used for complete directory trees. 2) The cpio skip corrupted file headers or skip over those files when I/O problems are encountered during restoration 3) Files are packed more efficiently with cpio, thus using lesser space. 4) The cpio is also used almost universally for backing up fie system. The tar is not used for device files. It is always preferable to maintain a file list for every backup. When user asks for particular file, from the list the administrator can look up for the particular file. FILE SYSTEM BACKUP In addition to routing backup, administrator has to back up individual file systems. Backup manager is a fairly complete system which lets the administrator schedule and implements his backups in a systematic manner. If the system crashes and UNIX has to be reinstalled, the administrator would not go through the tedious process of installing all peripherals separately. The root and boot file systems can be restore from the backup file. Q THE cpio COMMAND (COPY INPUT OUTPUT COMMAND) BACK UP PURPOSE The command can be used to copy files to and from a backup device. It uses standard input to take the list of filenames, and then copies them with their contents and headers, into a single archive that is written to the standard output. It can be used with piping and redirection. It uses two key options o and i. Backing up files By DHAVAL DALSANIA
Ls can be used to generate a list of filenames for cpio to use as input. The o option is used to create an archive which can be redirected to a device file. E.g. $ ls | cpio ov > /dev/rdsk/f0q18dt The v option makes cpio operate in verbose mode, so that the filenames is seen on the terminal when it is being copied. Incremental backup: find can also produce a file list, so any file that satisfy its selection criteria can be backed up. Multi-volume backup: when the created archive in the backup device is larger than the capacity of the device, cpio prompts for inserting a new diskette into the drive. When cpio pause to take input, the device name should be entered. If there are two floppy drives on a machine, user can alternate between two device names. Restoring files A complete archive or selected files can be restored with the i key option. To restore all the files that were backed up with a previous cpio command, the shells redirection operator (<) must be used to take input from the device. When restoring sub-directories, cpio assumes that the sub-directory structures are also maintained in the hard disk. But it can also create them if it is not present. The d option overwrites it. It also accepts a quoted wild-card pattern, so that multiple files fitting the patter can be restores. Preserving Modification Times: By default, when a file extracted, its modification time is set to the time of extraction. It would not be modified at the time of restoration. So it creates problem in incremental backup. The m option is used to restore last restoration time. Options -d -c -r -t -u -v -m -f exp -Csize Q Description Creates directories as and when needed Writes header information in ASCII character from portability Renames files in interactive manner Lists file in archive Overwrites newer file with older version Verbose option Retains original file modification time Copies all files except those in exp Sets input-output block size to size bytes
The command has been in existence before the emergence of cpio. Ti no only creates archives on tapes, but supports floppies as well. It does not write to the standard output, but crates an archive in the media. It is a versatile command with certain exclusive features no found in cpio. 1) It doesnt use standard input to obtain its file list. It accepts file and directory names as arguments 2) It copies one or more entire directory tree, i.e., it operates recursively 3) It can create several versions of the same file in a single archive 4) It can append to an archive without overwriting to entire archive It is used with a number of key optionsthe common ones are c (copy), -x (extract) and t (list). One and only one of these key options ha to be present. The f option is used to specify device name. Backing up files By DHAVAL DALSANIA
When files are copied with absolute pathnames. They can be restored in the same directory. But to change the directory user has to specify path. The advantage of tar is it can copy an entire directory tree with all its sub-directories, with or without hidden directories. The files here are backed up with their relative pathname, assuming that they all fie in one diskette. They do not accommodate them as much as possible. It quits program without warning. Multivolume backup: the k option is used for the purpose. Restoring files It can be accomplished using x option. When no file or directory name is specified, it restores all files from the backup device.
By DHAVAL DALSANIA
IP addresses are used by many utilities like telnet. But many applications usually access these machines by their names rather than IP address, because they are difficult remember. So they are given naming convention, which can be used by users.
OR
Q PRINTER MANAGEMENT (chap 26) It is an important part of the administrators job, and in large installation can often take a lot of time. UNIX provides a spooling sub-system featuring a number of commands which ensure that spooling takes place in an orderly manner. It involves managing the print queues, adding and removing printers, starting and stopping the sub-system. It must make of two following components: 1) Commands used by the user like lp, cancel 2) The administrator command like lpadmin, lpsched, lpshut, accepts and reject, enable and disable. No user is allowed direct access to the printer. One has to spool a job along with others in a print queue. Spooling ensures the orderly printing of jobs, relieving the user from the necessity of administering the usage of print resources. It is provided by lp command. E.g. $ lp chap01 request id is pr1-320 (1 file) The prompt is returned immediately after the job has been submitted. It notifies the request-id, a combination of the printer name (pr1) and the job number (320). The file is not actually printed at the time the command is invoked, depending upon the number of jobs already lined up in the queue. Several users can print their files in this way without conflict. The output from the printer would be a hard copy of the actual file with title page mentioning the username, request-id and date. The lp command accepts the request if a default printer has been defined by the administrator. If it has more than one printer, administrator has to specifies the name of printer. Option -d -t -m -n Description E.g. specifies the printer name. $ lp dlaser chap01 gives title to the first page. $ lp tHello chap01 it mails user after the file has been printed for multiple copies $ lp n3 m chap01
E.g.
To cancel any job cancel command is used. $ cancel laser cancels current job on printer laser $ cancel pr1-320 cancels job with ID pr1-320
Q DIVIDING A DISK INTO A PARTITIONS fdisk command (CHAP 25) The fdisk command is used to create, delete and activate partitions. The command is also used I n DOS for the same purpose, but operates different in Linux. Upto four partitions can be created in each hard disk. Q FILE SYSTEM CHECKING fsck COMAND (CHAP 25) By DHAVAL DALSANIA
The built-in UNIX feature of delaying the updations of the disk superblock by its inmemory copy leaves a lot of scpe for file system inconsistency. If the poser goes off before the superblock was written to disk, an incorrect superblock and often some inodes are left behind. The file system then loses its integrity and needs immediate rectification. The checking is done during the next startup. There are many differences that could lead to file system corruption, and the most common are: 1) A block marked as free but actually in use, or a used block marked as free 2) A block marked free, nor in use, or having a bad block number that is out of range 3) Two or more inodes claiming the same disk block 4) Mismatch between the file size specified in inode and the number of data blocks specified in the address array. 5) A file not having at least one directory entry or having an invalid file type specified in the inodes. The fsck command is used to check and repair a damaged file system. It checks in five phases, and the output is obtained when the file system is consistent. When the file is corrupted, messages and questions are seen on the system cosole. Q THE init PROCESS It is a daily job of an administrator. They are run by automated shell scripts which are changed quite infrequently. It is initiated at the time of system startup. The kernel is loaded into memory, and it then starts spawning further processes. It has PID 1, which is responsible for the birth of all subsequent processes. There are two main tasks of init processes. 1) It controls the system states and decides which processes to run for each state. 2) It spawns a getty process fro every terminal so that users can log in. It also makes sure that all system daemons are running. The lpsched command monitors the liner printer spooler for jobs that have been queued for printing. The cron command is the systems chronograph. The gated is the TCP/IP daemon which takes care of routing. The inetd is the master internet daemon, which spawns further daemons as and when required. While the init is parent of all these. It is also responsible for keeping the system in different states, called run levels. 1 System shutdown 2 System administration rule 3 Full multi-user mode in SCO UNIX 4 Full multi-user mode in LINUX 6 Shutdown and reboot mode S or s Single user mode When the system is booted, init first enters the run level 1 or S, it puts the system in single-user mode. This mode id used by the administrator to perform his administrative tasks (like checking the file system and taking an off-line backup). But it can use printer, file system can not be mounted, others users are prevented. It takes all its instructions from this file. Its fields determine the processes that should be spawned for each of the init states and the programs to run at the communication ports. Q MOUNTING AND UNMOUNTING
The interesting feature about a file system is, once it is created, it is a logically separate entity with its own tree structure and root directory. It is treated as a stand-alone mode; the main file system does not even know of its existence. These file systems unite to become a By DHAVAL DALSANIA
single file system at the time of booting. The root file system then becomes the main file system, and its root directory is the directory of the unified file system. It happens because of mounting process. When all these secondary file system attach them (mounted) to the main file at different points. The mount and unmount commands are used. The end result of mounting is that the user sees a single file system in front of herself, because the file movement is not between the hard disks. The mount command To mount file system to the root file system, an empty directory must first be made available in the main file system. The root directory of the new file system has be mounted on this directory. The point at which this linkage takes place is called the mount point. The mount command takes two arguments. 1) The name of the file system and 2) The directory under which it is to be mounted. The files are mounted at the start up time or manually. If rcmount is yes then the file system is mounted during startup. The mounting information can be created for the floppy drive and the CD-ROM also. The noauto option specifies that it is not mounted at the time of system startup. Option Description -f It is used to specify the type of file system that is to be mounted, which is necessary when CD-ROM is mounted -r It mounts a file system in read-only mode. -a all files in the directory
The unmount command Unmounting can be achieved with the umount command, which requires either the file sytem name or the mount point as argument. User can not unmount a file system unless user is placed above it. It is not possible to unmount the /usr file system as long as the file is being edited. File system are mounted during system startup, and unmounted when the system is shut down. If the file system is not clean, it will fail to mount, in which case it has to be checked for consistency. There is also a system configuration file which specifies how and when these file system are mounted an unmounted. Q USER MANAGEMENT The term user means the name of a project or an application, where a group of users having similar functions can use the same username to use the system. The UNIX system provides a number of services related to the creation and maintenance of user accounts. ADDING USER: useradd The administrator has to associate each user with a group, and the permissions must be decided that have to be set for both the user and her group. Adding a user involves setting of the following parameters: 1) An UID and User name 2) A GID and Group name 3) The home directory 4) The login shell 5) The mailbox By DHAVAL DALSANIA
6) The password It the user is placed in a new group, an entry for the group has to be created in /etc/group. It must have one primary group, and also secondary group. The file contains all the named groups of the system and few lines of the file. Option Description -u UID -g GID -c -d -s -m
By DHAVAL DALSANIA