Thursday, January 10, 2013

Unix Assignment Important Ques & Ans.

Ques-1 Discuss the feature of UNIX operating system that have made such phenomenally successful operating system?

Ans- The UNIX Operating System is available on machines with a wide range of computing power, from microcomputers to mainframes, and on different manufacture's machines. No other operating system can make this claim. We see the reasons of popularity and success of UNIX. The reasons are Portability: The system is written in high-level language making it easier to read, understand, change and, therefore move to other machines. The code can be changed and complied on a new machine. Customers can then choose from a wide variety of hardware vendors without being locked in with a particular vendor. Machine-independence: The System hides the machine architecture from the user, making it easier to write applications that can run on micros, mins and mainframes. Multi-User Operations: UNIX is a multi-user system designed to support a group of users simultaneously. The system allows for the sharing of processing power and peripheral resources, white at the same time providing excellent security features. Hierarchical File System: UNIX uses a hierarchical file structure to store information. This structure has the maximum flexibility in grouping information in a way that reflects its natural state. It allows for easy maintenance and efficient implementation. UNIX shell: UNIX has a simple user interface called the shell that has the power to provide the services that the user wants. It protects the user from having to know the intricate hardware details. Pipes and Filters: UNIX has facilities called Pipes and Filters which permit the user to create complex programs from simple programs. Utilities: UNIX has over 200 utility programs for various functions. New utilities can be built effortlessly by combining existing utilities. Software Development Tools: UNIX offers an excellent variety of tools for software development for all phases, from program editing to maintenance of software.



Ques-2 what is shell programming? Write a shell program to print all the contents of an existing text file in upper case.

 Ans-2 The shell programming language incorporates most of the feature that most modern day programming language offer. For example, it has local and global variables, control instructions, function, etc. if we are to execute a shell program we don’t need a separate compiler. The shell program we don’t need a separate compiler. The shell itself interprets the command in the shell program A shell script is a file containing a set of commands to be executed (run) by the shell in sequence as it reads the file. In its simplest form, a shell script is simply a way to save a set of commands that are often executed, such as the initialization commands for your login session that are stored in the .login script file, so you don't have to re-type the set every time we just want to run it. Instead, you simply run the script that contains all the commands. The most generic sense of the term shell means any program that users employ to type commands. A shell hides the details of the underlying operating system with the shell interface and manages the technical details of the operating system kernel interface, which is the lowest-level, or 'inner-most' component of most operating systems. In Unix-like operating systems users typically have many choices of command-line interpreters for interactive sessions. When a user logs in to the system, a shell program is automatically executed. The login shell may be customized for each user. In addition, a user is typically allowed to execute another shell program interactively. The Unix shell was unusual when it was introduced. It is both an interactive command language as well as a scripting programming language, and is used by the operating system as the facility to control (shell script) the execution of the system. Shells created for other operating systems than Unix, often provide similar functionality. The following shell program print all the contents of an existing text file in upper case.

echo Enter the filename
read filename
echo Contents of $filename before converting to uppercase
echo ----------------------------------------------------
cat $filename
echo ----------------------------------------------------
echo Contents of $filename after converting to uppercase
echo ---------------------------------------------------
tr '[a-z]''[A-Z]' < $filename
echo ---------------------------------------------------



Ques-3 Describe what grep command does? Illustrate its use with an original example.

Ans-3 grep is a command-line text-search utility originally written for Unix. The name comes from the ed (text editor) command g/re/p (global / regular expression / print). The grep command searches files or standard input globally for lines matching a given regular expression, and prints the lines to the program's standard output.

This is an example of a common usage of grep:
grep apple fruitlist.txt

 In this case, grep prints all lines containing the sequence of characters apple from the file fruitlist.txt; therefore lines containing pineapple or apples are also printed. The pattern specified as a grep argument is case sensitive by default, so this example's output does not include lines containing Apple (with a capital A) unless they also contain apple.
 
More than one file name may be specified as arguments to grep. For, example all files having the extension '.txt' in a given directory may be searched if the shell supports globbing by using an asterisk in place of the file name:

grep apple *.txt

Regular expressions can be used to match more complicated text patterns. The following prints all lines in the file that begin with the letter a, followed by any one character, followed by the letter sequence ple.

grep ^a.ple fruitlist.txt

As noted above, the name of grep derives from a usage in ed and related text editors. Before grep existed as a separate command, the same effect might have been achieved in an editor:

ed fruitlist.txt
g/^a.ple/p
q

where the second line is the command given to ed to print the relevant lines, and the third line is the command to exit from ed. Like most Unix commands, grep accepts options in the form of command-line arguments, to change many of its behaviors. For example, the option flag -i enables case-insensitive search (ignore case).

grep -i apple fruitlist.txt

This prints all lines containing apple regardless of capitalization. Selecting all lines containing apple as a word, i.e. surrounded' by white space (pineapple and apples do not match) may be accomplished with the -w option flag:

grep -w apple fruitlist.txt

But if fruitlist.txt contains apple as a word followed by hyphen (-) character, it is also matched.

cat fruitlist.txt

apple
apples
pineapple
apple-
apple-fruit
fruit-apple
grep -w apple fruitlist.txt
apple
apple-
apple-fruit
fruit-apple

Exact line match is performed with the -x option. Lines only containing exactly and solely apple are selected with a line-regexp instead of word-regexp:

cat fruitlist.txt

apple
apples
pineapple
apple-
apple-fruit
fruit-apple

grep -x apple fruitlist.txt

apple

The -v (lower-case v) option reverses the sense of the match and prints all lines that do not contain apple, as in this example.

grep -v apple fruitlist.txt

banana
pear
peach
orange



Ques-4 What is an i-node and what information is contained in it? Describe how named files are mapped to i-nodes. How is the information associating disc blocks with i-nodes represented? What restrictions are placed on name to i-node links to simplify file system recovery?

Answer- A file system relies on data structures that contain information about the files, beside the file content. The former is called metadata (data which describes data). Each file is associated with an inode, which is identified by an integer number, often referred to as an i-number or inode number.

Inodes store information about files and directories (folders), such as file ownership, access mode (read, write, execute permissions), and file type. On many types of file system implementations, the maximum number of inodes is fixed at file system creation, limiting the maximum number of files the file system can hold. A typical allocation heuristic for inodes in a file system is one percent of total size. File names and directory implications:
  • inodes do not contain file names, only file metadata.
  • Unix directories are lists of association structures, each of which contains one filename and one inode number.
  • The file system driver must search a directory looking for a particular filename and then convert the filename to the correct corresponding inode number.

Within each file system, the mapping from names to blocks is handled through a structure called an i-node. There's a pool of these things near the "bottom" (lowest-numbered blocks) of each file system (the very lowest ones are used for housekeeping and labeling purposes we won't describe here). Each i-node describes one file. File data blocks (including directories) live above the i-nodes (in higher-numbered blocks).

Every i-node contains a list of the disk block numbers in the file it describes. (Actually this is a half-truth, only correct for small files, but the rest of the details aren't important here.) Note that the i-node does not contain the name of the file.

Names of files live in directory structures. A directory structure just maps names to i-node numbers. This is why, in Unix, a file can have multiple true names (or hard links); they're just multiple directory entries that happen to point to the same i-node.

Unix permits you to give files many names ("links"); but, not directories. You are not allowed to create a hard link to a directory. Each directory inode is allowed to appear once in exactly one parent directory and no more. This restriction means that every sub-directory only has one parent directory, and that means the special name ".." (dot dot) in a sub-directory always refers unambiguously to its unique parent directory.

Hope you like this please do comments...................

3 comments:

  1. wel done bro,,,,,great effort, tremendous work,,,,
    big salute,,,,,,!!!!!

    ReplyDelete
  2. Thanks .. I will Keep updating Amity Assignments .. please share my website with your friend..
    Your valuable comments is my strength.. so keep commenting. :)

    ReplyDelete
  3. Great guys...
    Its mostly question are same in (AMITY UNIVERSITY DISTANCE ONLINE 2nd Sem).

    Thanks
    Izhar Saifi

    ReplyDelete