Professional Documents
Culture Documents
kernal:-the kernal is the core of the operating system-a collection of routines mostly written in c.these
routines communicate with the hardware directly.it is that part of the unix system that is loaded into
memory when the system is booted.user progams(the applications) that need to communicate with the
hardware(like the hard disk or the terminal) use the services of the kernal,which performs the job on
the user’s behalf.these programs access the kernal through a set of functions called system calls.kernal
also manages the system’s memory,schedules processes,decides their priorities.
Shell:-it is actually the interface between the user and the kernal.even though there’s only one kernal
running on the system, there could be several shells in action-one for each user who is logged in.
System calls: these are the functions to communicate with the kernal.often the same system call can
access both a file and a device.these system calls are built into the kernal, and interaction through them
represents an efficient means of communication with the system.
Ans: the POSIX (Portable Operating System Interface for Computer Environments) standard refers to
a group of related standards for operating systems in general, but was based on UNIX because UNIX
was supposedly free from bias on account of its vendor-neutrality.two of the most –cited standards
from the POSIX family are known as POSIX.1 and POSIX.2.POSIX.1 specifies the c application
program interface-the system calls.POSIX.2 deals with the shell and utilities.
The second entity is the process, which is the name given to a file when it is executed as a
program.like files, processes also belong to a separate hierarchical tree structure.
2
6. Pattern matching
7. Programming Facility
The UNIX shell is also a programming language.It has all the necessary ingredients, like
control structures, loops and variables, that establish it as a powerful programming language in
its own right.these features are used to design shell scripts-programs that also include UNIX
commands in their syntax
3
8. Documentation
The principle on-line help facility available is the man command, which remains the most
important reference for commands and their configuration files.
The execution of this vanishes whatever was typed and the prompt and cursor are positioned at
the top-left corner of the screen.
$ exit
login:
The login: message confirms that the session has been terminated, thus making it available for
the next user.
Ans: the commands having independent existence in the /bin directory (or /usr/bin), are called as an
external command.
For ex: ls command is an external command
Echo isn’t an external command in the sense that, when we type echo, the shell won’t look in its
PATH to locate it (even if it is there in /bin).Rather, it will execute it from its own set of built-in
commands that are not stored as separate files.these built-in commands, of which echo is a member are
known as internal commands.
ans: unix offers an on-line help facility in the man command.A man page is divided into a number of
compulsory and optional sections.Every command doesn’t have all sections but the first three( NAME,
SYNOPSIS and DESCRIPTION) are generally seen in all man pages.
4
NAME presents a one-line introduction to the command.
SYNOPSIS shows the syntax used by the command and DESCRIPTION (often the largest section)
provides a detailed description.the SYNOPSIS follows certain conventions and rules which every user
must understand:
If a command argument is enclosed in rectangular brackets, then it is optional;
otherwise, the argument is required.
The ellipsis (a set of three dots) implies that there can be more instances of the
preceding word.
If there is a | character in any of these areas, it means that only one of the options
shown on either side of the pipe can be used.
All options used by the command are listed in the OPTIONS section.There’s a separate section EXIT
STATUS which lists possible error conditions and their numeric representation.
$ Cal 03 2003
March 2003
S M Tu W Th F S
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
to display a message
to evaluate shell variables
echo interprets certain strings known as escape sequences.
An escape sequence is generally a two character-string beginning with a \ (backslash).
printf:
The command in its simplest form can be used in the same way as echo:
$ Printf “No filename entered\n”
No filename entered
$ _
printf also accepts all escape sequences used by echo.printf uses many of the formats used by C’s
printf function.
%s string
%30s as above but printed in a space 30 characters wide
%d decimal integer
%6d as above but printed in a space 6 characters wide
%o octal integer
%x hexadecimal integer
%f floating point number
bc: bc belongs to a family of commands that expect input from the keyboard when used without an
rgument.key in the following arithmetic expression and then use [Ctrl-d] to quit bc:
$ bc
12 + 5
17
[Ctrl-d]
$ _
To enable floating-point computation, the sacle have to be set to the number of digits of precision
Scale=2
17/7
6
2.42
ibase=2
11001010
202 ;output in decimal-base 10
obase=2
14
1110
This command tells the filename of the terminal you are using
$tty
/dev/pts/10
The terminal filename is 10 resident in the pts directory.the directory in turn is under the /dev
directory. Tty is used in a shell script to control the behaviour of the script depending on the terminal it
is invoked from.
5. Explain date, uname, sttty, who, script commands with options and example
10
Ans: date: we can display the current date with the date command, which shows the date and time to
the nearest second:
$ Date
Tue Dec 10 18:52:26 IST 2002
$ date +%m
12
$ date +%h
Dec
Uname: the command displays certain features of the operating system running on your machine. By
default, it displays the name of the operating system:
$ uname
SunOS
The Current Release and Implementation Name (-r and –s): the –r option is used to find the version of
your operating system
$ uname -r
5.8
The implementation name of this operating system can be obtained with the –s option
$ uname -s
SunOS
The Machine Name (-n): if your machine is connected to a network, then it must have aname (called
hostname).-n option tells the hostname
$ uname -n
mercury
$ who
The first column shows the usernames (or user-id), the second column shows the device names of their
respective terminals, the third, fourth and fifth columns show the date and time of logging in.the last
column shows the machine name from where the user logged in.
(-H) option prints the column header.
To know the user who invoked the who command use the arguments am and I with who:
$ who am i
kumar pts/10 Aug 1 07:56 (pc123.heavens.com)
$ script
Script started, file is typescript
$ _
The prompt returns and all your keystrokes that you noe enter here get recorded in the file typescript.
Script –a
Ans: the file is a container of information or a sequenceof charactersunix treats directories and devices
as files as well.
ordinary file:an ordinary file itself can be divided into two types:
.text file:a text file contains only printable characters.all C and Java program sources,
shell and per1 scripts are text files.
.binary file:a binary file contains both printable and unprintable characters that cover
the entire ASCII range. Most UNIX commands are binary files, and the object code and
excutables that you produce by compiling C programs are also binary files.
Pictures, sounds and video files are binary files as well.
Directory file:a directory contains no data, but keeps some details of the files and subdirectories
that it contains.
A directory file contains an enty for every file and subdirectory that it houses.each entry
has two components:
. The filename
.a unique identification number for the file or directory.
Device file:
9
Device filenames are generally found inside a single directory structure, /dev.it is
advantageous to treat devices as files as some of the commands used to access an ordinary
file also work with device files.the kernal identifies a device from its attributes and then
uses them to operate the device.
Ans: the file system in unix is a collection of all the related files (ordinary, directory and device files)
organized in a hierarchical structure.the implicit feature of every unix file system is that there is a top,
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.
The root directory(/) has a number of subdirectories under it.these subdirectories, in turn , have more
subdirectories and other files under them.every file apart from the root,must have a parent,and it should
be possible to trace the ultimate parentage of a file to root.
7.explain the following commands with options and suitable example pwd,wc,cp,rm,more
10
$ pwd
/home/kumar
pwd displays the absolute pathname.
wc:wc command counts lines,words,and characters,depending on the options used. It takes one or
more filenames as its arguments, and displays a four-columnar output.
$ wc infile
3 20 103 infile
wc counts 3 lines,20 words and 103 characters.
wc offers three options to make a specific count.the –l option counts only the number of lines, while
the –w and –c options counts words and characters respectively:
$ wc -l infile
3 infile
$ wc -w infile
20 infile
$ wc -c infile
103 infile
when used with multiple filenames, wc produce a line for each file,as well as a total count.
10
cp: the cp command copies a file or a group of files.it creates an exact image of the file on disk with a
different name. the syntax requires at least two filename to be specified in the command line.
When both are ordinary files,the first is copied to the second
Cp chap01 until
If the destination file(until) doesn’t exist, it will first be created before copying takes place.
Interactive copying (-i): the –i option warns the user before overwriting the destination file.
$ cp -i chap01 until
Copying directory structure (-R): it’s possible to copy an entire directory structure with the –R option.
cp -R progs newprogs
rm: files can be deleted with rm .it can delete more than file with a single invocation.the following
command deletes the first three chapter of the book:
Interactive deletion (-i): the –i option makes the command ask the user for confirmation before
removing each file.
Recursive deletion (-r or –R): with the –r (or –R) option, rm performs a tree walk – a through recursive
search for all subdirectories and files within these subdirectories.at each step it deletes everything it
finds.
Forcing removal (-f): rm will prompt you for removal if a file is write-protected.the –f option overrides
this minor protection also.
More chap01
The contents of chap01 is displayed on the screen,one page at a time.at the bottom of the screen,you’ll
also see the filename and the percentage of the file that has been viewed.
--more—(17%)
to move forward one page,use f or spacebar & b to move back one page.10f can be used to scroll
forward by 10 pages & 30b for scrolling back 30 pages.
More has a repeat command, the dot that repeats the last command you used
Ans: ls command is used to list the names of the files available in the directory
$ ls -x
ls with –a option lists all hidden files all with the other files.
Ans: If the first character of a pathname is a /, the file‘s location must be determined with respect to
root. Such a pathname is called an absolute pathname.
The relative pathname uses either the current or parent directory as reference and specifies the path
relative to it.a relative pathnames uses one of these cryptic symbols:
. (a single dot)- This represents the current directory.
..(two dots)-this represents the parent directory.
Aruments are the additional words used along with the commands UNIX command use a filename as
argument so the command can take input from the file.
Options are special type of argument that’s mostly used with a – sign. For ex;
ls -l note
Ans: file command is used to determaine the type of file (regular, directory or device)
$ file archive.zip
archive.zip: ZIP archive
File recognizes text files, and can distinguish between shell programs,c source and object code.it also
identifies DOS executables,compressed files,PDF documents and even empty files.
HOME variable: home directory is created by the system when a user account is opened.the shell
variable HOME knows your current directory.the home directory is determined by the
systemadministrator at the time of opening a user account.