1.What is a process? Explain the mechanism of process creation in UNIX system.
Ans::A process is born when a program starts execution and
exists as long as the program is running. After execution the
process is usuallythe name of the program being executed. A
process executes for a finite period of time and then gives
control to another process.
The creation of process is in three phases and uses three system known as fork, exec and wait. Fork is system calls that create a new process from an existing process. The new process is called child process, and the existing process is parent. The attribute of the parent and child are identical except the parameter like PID. The child gets new PID when process is forked. The child process overwrites the image with a copy of the program that is to be executed by using the exec system call. The parent process to wait for the child process to get completed executes the wait system call. The parent process picks up the exit status of the child process.
2.What is the significance of write and talk command in UNIX.
Ans: Write and Talk command are communication programs that allow users to talk to each other in network.The write command copies lines from one users terminal to that of another user. The command is used by typing the following command:$ write username Where username is another logged in user. (P) The program talk is visual communication program, which copies lines from the user’s terminal that of another user. It allows text-based communication between two users. e.g. if user1 wishes to talk to user2 who would be logged into system, user1 types the following: $ talk user2
THE INPUT MODE:--Command—Function // i-Insert text to before cursor. //a-append text after cursor. //I-insert text before first non-blank character. //A- append text at end of line. // o -open a new line below. //O -open a new line above. //r- replace single char under cursor.//R -replace characters from cursor onwards. //s- replace single character with characters. //S -replace entire line.
3. WHAT IS THE WILD-CARDS----Wildcards are a special set of characters used by the shell to match filenames. A wildcard “stands in” for other characters of the filename. The filenames pattern is formed by ordinary characters and metacharacters using well defined rules. When the pattern is used as an argument with a command, theshell first suitably expands the argument and then executes the command. The use of wildcards makes iteasier to deal with files in Unix. File names can be abbreviated using wildcards. The shell’s wildcards arelisted below:
wildcard what it matches
* any number of characters—including zero characters.
? a single character
[abc] a single character- either a, b or c
[a-d] any single character in the range a to d
[!abc] a single character that is not a or b or c
[!a-d] any character not in the range a to d
The question mark, ‘?’, stands in for any single character. For example, suppose there are three files, file1, file2 and file12 in a directory. The ls command with file? As argument will display the following:--//$ ls file?//file1 file2 //file12 will not be listed because the question mark can stand in for either ‘1‘ or ‘2’, but not both at the same time.
1. With any five examples, explain the use of wild cards in UNIX. 5 Marks
Ans: The wild cards are used to match a given pattern. The different types of wildcard characters used in UNIX are following:
* | Represents any number of character any number of times. |
? | Represents a single character. |
[abc] | Represents a single character either a, b, c |
[a-d] | Represents a single character in the range of a or b or c or d |
[!abc] | Represents a single character that is not a, b, c |
[!a-d] | Represents a single character that is not in the range of a or b or c or d |
ls file* list all file which begins with file and ends with anything.
ls file? list all files which name has five character but first four character is file.
rm file* removes all file whose name starts with file and conatins anything after that.
rm *.txt removes all the files ending with .txt.
ls file[1-4] list all file beginning with file and ending within the range of 1 to 4
ls file[143] list all file beginning with file and ending with either 1 or 4 or 3.
4. WHAT IS SHELL VARIABLES------
A shell variable is a memory storage area that can be used to hold a value. A shell variable can be an environment variable or a user-defined variable. //// The environment shell variables tell the shell about the way an user account is set up. Some of the commonly used environment variables are listed as follows:
variable value held
HOME pathname of the home directory
SHELL pathname of the shell (/bin/sh)
PATH list of directories where shell looks
For commands
TERM terminal type
USER user name
MAIL pathname of the system mailbox
Some of the environment shell variables like HOME and SHELL are set automatically when the user logs in. Other variable like TERM maybe set by the user.Example:--If the user is working on a terminal of type vt100, the variable TERM is set to vt100.
//$ TERM=vt100//$ export TERM
Users can define their own variables by giving the variable a name and value.User-defined variable
names should begin with a letter and can contain letters, numbers and the underscore (_) character. Variable names are case-sensitive and are all of type string. Numbers are also stored as strings, The default value of a shell variable is always a null string. The syntax to assign a value to a variable is as follows: Variable=value // There should be no space on either side of the = character. To display the value assigned to a variable, the name of the variable is preceded by a $. In a command line, any word preceded by a $ is recognized as a variable by the shell and replaces the word by its value.Example:-- Assign the value 100 to the variable abc//$ abc=100
display the value assigned to the variable abc//$ echo $abc
The value stored in one variable can be assigned to another variable.//$ xyz=$abc//$ echo $xyz
assign a null string to a variable abc//$ abc=
A variable can be removed by using the shell internal command, unset.//$ unset abc
A multiword string can be assigned to a variable by the use of single quotes.Ex:// $ abc=’This is a multiword string’
5. With a neat diagram explain the organization of UNIX file system. 8 Marks The filesystem tree ----
You can visualize the Unix file system as an upside down tree. At the very top of the tree is the root directory, named "/". This special directory is maintained by the Unix system administrator. Under the root directory, subdirectories organize the files and subdirectories on the system. The names of these subdirectories might be any name at all. Here is a tree diagram of a typical Unix system.
the root directory / has four subdirectories: bin, tmp, users, and src
Relative and Absolute Pathnames ---
Relative Pathnames ---The use of the ".." notation allows me to navigate the directory tree structure. The ".." symbol means "parent directory." Names with ".." in them are relative names because their meaning depends on where they are issued (the present working directory). I can string together several ".." symbols, separated by the / symbol and other directory names, to change directories
Directory or file references starting with .. are relative pathnames.
Directory or file references starting with a directory name are also relative pathnames
Absolute Pathnames ----
If I string together the unique name of all the intervening subdirectories in the file system to a particular subdirectory, I've created the absolute pathname for that directory. The absolute pathname allows me to switch to a directory no matter what my present working directory is. Absolute pathnames always start with a "/".
6.THE MODES OF VI THREE TYPES….::The three modes of vi are the command mode, the input mode and the ex or last line mode.
(1)command mode ---is the default vi mode. Every key pressed in this mode is interpreted as a command to be executed on the text. The key pressed is not displayed on the screen. If the [Esc] key is pressed in this mode, a beep is sounded. Commands can be given to perform functions like moving the cursor around the screen, delete lines, words or characters, etc.
(2)input mode-- is used to enter text. Every key pressed after entering this mode is displayed on the screen. After completing text entry, the cursor is positioned on the last character of the last line. This line is called the current line and the cursor position is called the current cursor position. The [backspace] key moves the cursor backwards and wipes out the character entered. To return back to the command mode, [Esc] key is pressed.
(3)ex mode or the last line mode ---is used to enter and run commands like saving files, reading files, text replacing, exiting vi, etc. The text entered in the input mode resides in a temporary storage called the buffer. To save text to a file, from the command mode, the user has to change to the ex mode which is done by entering a colon followed by the save command and the [Enter] key. After the command is executed, vi returns to the command mode.
7. UNIX History ( Full ….), like other operating systems, is a layer between the hardware and the applications that run on the computer. UNIX operating systems consists of kernel, shell, hardware and application program. It’sBasically two things: internal implementation and the interface that is seen and used by users.
The part of UNIX that manages the hardware and the executing processes is called the kernel. It is the core of UNIX operating systems . The kernel is a collection of programs written in C which directly communicate with the hardware. Application programs (user programs) communicate with the hardware by using the services of the kernel. Along with the memory management, the kernel also schedules processes and decides their priorities. In executing processes the kernel allocates resources, including use of the CPU and mediates accesses to the hardware.
The user commands are translated into action by the shell which acts as an interpreter. The shell forms the outer part of the operating system and forms the interface between the user and the kernel. For each user logged in, there is shell in action. When a command is given by the user, it is examined by the shell and communicated to the kernel for execution. The functions used to communicate with the kernel are called system calls and are built into the kernel.
The very top of the UNIX directory structure is called the root directory referred to as “slash.” (/).This directory is full of other directories. Most of these directories are created at the time of installationand contain critical user functions. /bin and /usr/bin are directories where all the commonly used commands are located. Since most of the command files are binary files, the directory is called bin. /sbin and /usr/sbin are directories which contain commands that only the system administrator can execute. /etc directory has the configuration files of the system. The login names and passwords are stored in the file /etc/passwd and /etc/shadow. /dev contains all the device files. These files do not occupy any system space. /lib and /usr/lib contain library files in a binary form. Programs written in C use these library routines. /usr/include contains all the header files used by C programs. /tmp is directory where users can create temporary files. /var contains variable data like print requests, incoming and outgoing mail
grep options:-grep is one of the most important UNIX commands.it searches a file for specific PATTERN of characters and display the lines that contain that pattern. Syntax: $grep [option] [pattern] fine_name
Option Description
-i Ignores case for matching. $ grep -i “anantha” emp.lst 1005|S.K.Anantha |Asst.Prof. | I/F/M Science|20/07/63|24000
-v Doesn’t display lines matching expression
$ grep -v “Lecturer” emp.lst > otherlist
1001|T.N.Raju |Professor | I/F/M Science|14/06/61|30000 1005|S.K.Anantha |Asst.Prof. | I/F/M Science|20/07/63|24000
-n Displays line numbers along with lines.
$ grep -n “Lecturer” emp.lst
2:1004|D.S.Raghu |Lecturer |I/F/M Science |05/12/75|17000
4:1009|M.P.Rajendra|Lecturer |C/P Science |13/03/66|20000
-c Displays count of number of occurrences
e.g:--$ grep -c “Lecturer” emp.lst //2
-e exp Specifies expression exp with this option. Can use
multiple times. Also used for matching expression
beginning with a hyphen.
$ grep -e “mallu” -e “MALLU” emp.lst
1002|Mallu |Lecturer | I/F/M Science|20/07/74|15000
8. REDIRECTION::-- Redirection changes the assignments for the standardinput , output and error . using redirection , input to a command can be taken from a file other then the keyboard similarly , the output of a command or error can be written to a file or printed in sted of being displayed on the monitor . the three types of redirection are :-Input redirection , output redirection , Error redirection.
9..INPUT REDIRECTION :-The following erample illustrates the use of input redirection :- &$cat
10.Explain architecture of UNIX. 5 Marks
Ans: UNIX like other operating system is a layer between hardware and application that run on the computer. UNIX has function that manages hardware and application. The main difference between UNIX and other operating system is its implementation and its interface. The part of the UNIX that manages hardware and executing process is called kernel which is a collection of program written in C. Kernel communicates with hardware and application uses the services of the kernel to communicate with hardware. Kernel manages memory, decides priorities and schedules process. In UNIX each hardware device is a file. It maintains simple method of reading and writing file for accessing hardware. Many command used to access ordinary file works to access these file also. For every logged user a shell runs. Shell is an interpreter which executes all the command entered by the user. Shell forms the interface between user and application. Shell communicates with the kernel for execution of command using the function called system call. UNIX provides application portability means it allow the execution of same program on different type of computer hardware without modification. It can be achieved if the operating system is UNIX. The UNIX layer architecture hides the application from hardware
11.Explain cmp command with suitable examples with options. 5 Marks
Ans: cmp command is used to compare two compare two files. By default cmp is silent means it produces no output on the screen if two files are same. But if the file differs then byte number and line number at which difference occurs is displayed. The numbering of line and bytes starts with one. It has option l by which the displays the byte number in decimal and differing byte in octal.
Example of cmp command using options:
cat fruits1
apple
mango
pineapple
orange
cat fruits2
apple
grapes
pineapple
orange
$ cmp fruit1 fruit2
fruit1 fruit2 differ: char 7,line 2
12…Explain chmod command with suitable examples. 7 Marks
Ans: chmod command is used to change the permission of a directory or a file. The permission can be read, write and execute which is represented using r,w and x respectively. The user who is the owner of file or directory has rights to change the permission. Chmod has two types. One is symbolic mode which is made up of letters and operators. The other is absolute mode which is made up of numbers. It has the option R which recursively changes the file permissions.
The syntax of chmod command in symbolic mode:
chmod [–R] [category] [operator] [permission] file
In the symbolic mode the category can be one of the following:
a stands for all users.
u stands for the owner of file
g stands for the group to which the owner of file belongs.
o stands for group other than user.
In absolute mode each type of permission is an octal number. For each category, the permissions are assigned by adding the octal numbers representing the following:
4 sets read permission.
2 sets write permission.
1 sets execute permission.
Examples of chmod in symbolic mode:
To set execute permission for every one for file emp.lst in symbolic mode
chmod a+x emp.lst
To set execute permission for every one for file emp.lst in absolute mode
chmod 111 emp.lst
What is the difference between Hard link and symbolic link. 5 Marks.
During the creation a hard link no new file is created and the idone numbers of two are same. It is not created across file system. It prevents the accidental deletion of a file. If the source file is deleted that can be recovered using hard link file. During the creation a soft link a new file is created and the idone number of two different. It is created across file system. If the source file is deleted then the link file acts as a dangling file.
With a neat diagram explain different layers of UNIX operating system? Also explain interaction between shell and kernel using any suitable command. 15 Marks
Ans:
UNIX like other operating system is a layer between hardware and application that run on the computer. UNIX has function that manages hardware and application. The main difference between UNIX and other operating system is its implementation and its interface. The part of the UNIX that manages hardware and executing process is called kernel which is a collection of program written in C. Kernel communicates with hardware and application uses the services of the kernel to communicate with hardware. Kernel manages memory, decides priorities and schedules process. In UNIX each hardware device is a file. It maintains simple method of reading and writing file for accessing hardware. Many command used to access ordinary file works to access these file also. For every logged user a shell runs. Shell is an interpreter which executes all the command entered by the user. Shell forms the interface between user and application. Shell communicates with the kernel for execution of command using the function called system call. UNIX provides application portability means it allow the execution of same program on different type of computer hardware without modification. It can be achieved if the operating system is UNIX. The UNIX layer architecture hides the application from hardware.
Interaction between shell and kernel:
When a user login a shell start running for that user. When a command is entered by the user the shell scans the command for Meta characters which has special meaning to shell. After processing Meta characters the shell transfers the command to kernel for execution. When a type cat is entered on $ prompt then shell interprets the command and search the search path in system variable called PATH. After searched is finish it is given to the kernel for the execution.
The adept user can customise his/her own shell, and users can use different shells on the same machine. Students have the csh shell by default.
What are standard input, standard output and standard error? Give a command to redirectstandard error to working terminal and no where. ? Ans---Each process opens three standard "files": standard input (stdin), standard output (stdout), and standard error (stderr). Programs use these as follows:
Standard input is the place from which the program expects to read its input. By default, processes read stdin from the keyboard.
Standard output is the place the program writes its output. By default, processes write stdout to the terminal screen.
Standard error is the place the program writes its error messages. By default, processes write stderr to the terminal screen.
addition to the standard input and standard output, commands often produce other types of output, such as error or status messages known as diagnostic output. Like standard output, standard error output is written to the screen unless it is redirected.To redirect standard error or other output, use a file descriptor. A file descriptor is a number associated with each of the I/O files that a command ordinarily uses. File descriptors can also be specified to redirect standard input and standard output, but are already the default values. The following numbers are associated with standard input, output, and error:
0 | Standard input (keyboard) |
1 | Standard output (display) |
2 | Standard error (display) |
redirect standard error output, type the file descriptor number 2 in front of the output or append redirection symbols (> or > >) and a file name after the symbol. For example, the following command takes the standard error output from the cc command where it is used to compile the testfile.c file and appends it to the end of the ERRORS file:
cc testfile.c 2 >> ERRORS
Other types of output can also be redirected using the file descriptors from 0 through 9. For example, if the cmd command writes output to file descriptor 9, you can redirect that output to the savedata file with the following command:cmd 9> savedata
If a command writes to more than one output, you can independently redirect each one. Suppose that a command directs its standard output to file descriptor 1, directs its standard error output to file descriptor 2, and builds a data file on file descriptor 9. The following command line redirects each of these outputs to a different file:
command > standard 2> error 9> data
If you have a file with filename chap*. Give a command to remove that file. Also give reasons for not to have special characters like * ? etc in filename. 7 Marks
Ans: The command to remove a file with filename chap* will be $ rm chap\*
The file cannot contains the special symbols like ?, *, #, &, \, |,( ), [], { },$,<, >, etc as filename because these characters have special meaning to the shell. If any file contains these special symbols as filename then shell should take the special character literally. There are two ways of doing this –precede the special character by a backslash (\) or enclose the special character in a single quote (‘).
2. Explain the use of pipes and tees to connect commands?
Ans: pipe command is defined by two file descriptor one is open for output and another for input. The output from one process goes an input to another process which means that data goes from one end of the pipe an comes out of the other. The data flowing in a pipe are directly managed by the kernel. The shell connects the input and output a special pipe character |tee command is used to save the output of a command in a file or to pipe it an input for other command. tee is an external command and can be placed anywhere in a pipe. With tee command a user can display the output on the screen and can save the output to a file.
Use of pipe and tee to connect command:
$ ls –l | tee listfile passes the output of ls –l command as an input to tee command where tee command saves the output to a file listfile and displays the output to the screen.
sort myfile | tee sortfile the sort command sorts file myfile and pipe the output to the tee command as an input where tee command saves the output in a file sortfile and displays the output to a file sortfile.
3. What are internal and external commands? Give a reason why command cd cannot be an external command. ?
Internal commands are built in shell. Shell does not run any other process to run built in commands. They take less time in their execution where as external commands are not built in shell. Shell runs other process for their execution. They take more time in their execution. cd cannot be an external command because it is built in shell that means the shell interprets the command and change the current directory.
Write a shell program to find biggest of three numbers.?
Ans:
echo "Enter first number"
read num1
echo "Enter second number"
read num2
echo "Enter third number"
read num3
if test $num1 -gt $num2 -a $num1 -gt $num3
then
echo "$num1 is greater than $num2 and $num3"
elif test $num2 -gt $num1 -a $num2 -gt $num3
then
echo "$num2 is greater than $num1 and $num3"
elif test $num3 -gt $num1 -a $num3 -gt $num1
then
echo "$num3 is the greatest"
else
echo " "
fi
4. Explain the following filters
Write short notes on the following:
pr: The pr command prepares a file for printing by adding suitable headers, footers and formatted text. This command has to be used with a file name as argument. pr adds five lines of margin at the top and five at the bottom. The header shows the date and time of last modification of the file along with the file name and page number. There is one option that uses a number prefixed by a + to print from a specific page number. Another option –l set the page length.
Example:
$ pr emp.lst will shows date and time, file name and page number as header.
$ pr –l 54 emp.lst sets the printing of file from 54 lines
$ pr +5 emp.lst starts printing from page 5
cat: cat command is used to concatenates or display the contents of a file. The syntax of cat is
cat [-v] filename
The cat command normally used to display the contents of text files. With –v option, non printing characters can also be displayed. cat command can be used to create files. cat command is used to append to an existing file.
Example:
$ cat file1
Displays the contents of a file.
$ cat > file2
Creates a file2 and when entered is pressed cat waits for user to type in the file. The file is saved and closed using ctrl-d.
$ cat >> file2
Appends to the file2
head: The head command is used to show the top of a file. When head command is used without any argument then it displays top 10 lines of the file by default. head command uses option –n to display first n number of lines of a file.
Example:
$ head file1 shows first ten lines from file file1.
$ head –n 5 kalpa shows first 5 lines from file kalpa.
tail : The tail command is used to show the end of a file. when tail command is used without any argument then it displays last 10 lines of the file. tail can be used to display lines from the beginning of the file instead of the end. The + count option allow to do that where count represents the line number from where the selection should begin. tail command uses option –n to display last n number of lines of a file.
example of tail command:
$ tail saurabh displays last 10 lines by default.
$ tail –n 5 saurabh displays last 5 lines by default.
$ tail +5 saurabh displays from fifth line to the end of the file.
grep: grep command is used to search for a pattern in a given file. it displays the selected pattern, the line numbers or the filenames where the patterns occurs. The syntax of gerp is
grep options pattern filename(s)
grep searches for a pattern in a given file. The first argument is pattern and other is filename.
gerp options:
ignore case(i): it searches for a pattern ignoring the case of the searching pattern.
Example:
grep –i “kumar” emp.lst
output: KUMAR
deleting lines(-v): grep can play inverse role too, the –v option selects all excepts lines containing the pattern.
Displaying line number (-n): The –n option displays the line numbers and line of searched pattern.
Counting lines containing pattern(-c): The –c counts the number of line containing the pattern.
tr: The tr (translate) filter manipulates individual characters in a line. It translates characters based on expression specified. The general form is tr expression1 expression2 standard input
tr takes input only from standard input. It does not take filename as argument. By default it translates each character in expression1 to its mapped counterpart in expression2.
sort: sort command sort a file based on a condition. The sort uses space as default field separator.
Sorting on primary key(-k): To sort second field of a file shortlist the following command can be written
sort –t “|” -k 2 shortlist
To sort in reverse order –r option is used.
sort –t “|” –r -k 2 shortlist
Sorting on secondary key(-k): Sorting can be done on more than one key. If the primary key is third column and secondary key is the second field then following command is written
Sort –t “|” –k 3,3 –k ,2,2 shortlist
Numeric sort(-n): When sort acts on numerals then ASCII collating sequence place 1 above 2, and 2 above 4 and so on.
sort numfile produces output
10
2
4
But sort –n numfile will produce output like
2
4
10
-t char use delimiter char to identify fields
-k n sorts on n field
-k m,n starts sort on m field and ends sort on n field
-k m.n sort on n column of m field
-n numeric sort
-r reverse sort
-m list merge sorted list
-c check if file is sorted
-o filename places output in a file
Uniq: uniq simply writes unique copy of each line from a file to standard output. Uniq requires a sorted file as input. The general procedure is to sort the file and pipe it to uniq.
set: Positional parameter are sometimes called read only variables because shell sets their values when argument is typed. But value of argument can be set by the user itself using set command. As for example
#!/bin/sh
set `date`
echo “Time: $4$5”
here the backquotes runs the date command and catches the output and stores it in the positional parameter.
Pine: pine is a character and menu base mailer. To create a mail using pine letter C is pressed then the address of the recipient is entered and if it is to be sent to more than one recipient then the address in entered. Any file can be attached then after subject of mail is entered which should be small. The message body is entered and it is send by pressing ctrl-c. A confirmation is asked before the delivery of mail. Pressing Y will send the mail and N cancels the delivery. The first column shows a + or blank specifying that a copy is sent or not. The second column gives the status of the message. N for new, A for answered and S for saved. The third column gives sender name and fourth column gives the date and time whereas fifth column specifies the size.
To read a mail the mail is selected first then V is pressed this opens the mail for reading. To view an attachment V is pressed this list the attachment and to read an attachment, the attachment is first selected then V is pressed again. To exit attachment viewer and attachment index E is pressed twice. To reply a message R is pressed. To save a message S is pressed. To quit a pine Q is pressed.
Mailx: mailx is an command line tool which can run interactively from shell scripts. Mailx can run in sending as well as running mode. Typing mailx user1 prompts user for subject of message. The message body is then entered. Ctrl-d denotes the end of message body. Mailx can be used to send mail interactively with option –s. To receive mail using mailx the command is used without any argument. The first column gives the status of message where N denotes new mail, U denotes an unread old mail. The second column gives the mail number. Third column gives sender name, fourth column gives the date and time of mail received and fifth gives the lines and character the mail contains.
script: script command is used to record a login session of a user. The different option that script command uses are following:
syntax of script command:
script [option] [argument]
when script command is used without any option and argument then script is saved to a default file called typescript.
script filename: writes the login session to the given filename.
script –a filename records the login session to the existing filename. passwd: passwd command is used to change the password of a user. System administrator can change the password of any one. The system prompts the user for old password and if the old password is entered correctly. The system prompts the user for new password and prompts the user to reenter the new password. If the new password entered gets matched then password is changed otherwise rejected.
who: who command without any option returns the users logged currently on the system with their name, terminal number, date and time of login.
Who am i returns the name of a user logged on a system along with terminal name, date and time.
Who –q list the name and number of user logged.
Tput-----query the terminfo database.
tput cols : prints the number of columns for the current terminal.
tput clear: clears the screen.
Lock-------- is used to lock a user terminal. The syntax for lock command is lock [-v] [number]. Lock command prompts the user for password and request it again for confirmation and then locks the terminal until password is reentered. If the number is given in locked command then terminal automatically logs out after given time.
$ lock
Password:
Re-enter password:
Terminal locked by user 0 minutes ago.
lock –v specifies verbose operation.
$ lock -v
Password:
Re-enter password:
Terminal locked by user 0 minutes ago.
Terminal is logged out after 10 minutes.
$ lock -10
Password:
Re-enter password:
Terminal locked by user 0 minutes ago.
Pipes: A pipeline is the simplest and most used inter process communication mechanism in UNIX. A pipe is a communication channel defined by two file descriptors, one is open for output and one is for input. The output from one process goes an input to another process which means that data goes from one end of the pipe an comes out of the other. The data flowing in a pipe are directly managed by the kernel. The shell connects the input and output a special pipe character |.
Pipes are used to avoid writing temporary files to communicate between programs.
Example:
$ ls –la | more which takes the standard output from the ls command and transfers it to the standard input of the more command. The more command list the file one page at a time.
What is long form of POSIX. ?-----POSIX stands for Portable Operating System Interface for UniX. It is an IEEE 1003.1 standard that defines the language interface between application programs and the Unix operating system. Adherence to the POSIX ensures compatibility when programs are moved/migrated from one unix computer to another.
Why does a computer require an O.S. ? -------A computer requires an operating system to control the various hardware devices and manage its own resources. The operating system also allows users to create and manage files and run various applications. The operating system performs the following basic tasks:
1. Peripheral Management
2. Memory Management
3. Process Management
4. File system Management
Command Interpretation
. How are commands located in unix ? -----A command can be located by using the type command. For example to get the location ofcommand in the Unix system, the following command is entered-
$ type cat
cat is /bin/cat
When the cat command is entered, the shell searches for the command in the search path.
. How do you check a file for spelling errors. ?---- A file can be checked for spelling errors by using the ispell command. Example: List the misspelt words in the file infile
$ spell infile
ispell - find spelling errors
Syntax
ispell filename
Can a directory by removed if it is not empty ?----------No, a directory must be empty, if you want to delete it.@The rmdir command does @ not work unless the directory to be removed is completely empty. A directory can be removed only if itis hierarchically below the working directory. Example: remove the directory textfiles which should be empty
@$ rmdir textfiles-----Example: remove the directory set1 from the directory cprog
$ rmdir cprog/set1
Why is the size of a directory file small ? ---------The size of a directory file is small because a directory file contains the name and the i-number of each item (file or subdirectory) contained within the directory.
How do you yank and paste the lines ?------------To yank and paste the lines, perform the following steps:
A. Keep the cursor at the line you want to copy.
b. Press Y or
c. Place the cursor at the line, where you want to paste the copied lines.
d. Press p to paste the line after the cursor or press P to paste the lines before the cursor.
Where is the password stored and in what form?
Ans: The password is stored in /etc/passwd and in the binary form.
What the use of tee command.?
Ans: tee command is used to save the output of a command in a file or to pipe it an input for other command. tee is an external command and can be placed anywhere in a pipe. With tee command a user can display the output on the screen and can save the output to a file.
Display the current date in dd/mm/yyyy and mm-dd-yyyy formats. ?
Ans: date +%D , date +%m-%d-%Y
How do you change the user password and where is the password stored?
Ans: user password is changed using passwd command and is stored in /etc/passwd.
What is the command to display output one screenful at a time.?
Ans: more
What is PATH variable? What is its use?
Ans: PATH is an environmental variable. It contains the list of directories where shell looks for command.
1. How you do the following in Job control
a) Running process in Background
b) Stopping process executing in foreground
c) Taking stopped job to background
d) Bringing background job to foreground
. What is the mountable filesystem in UNIX?---------UNIX operating system has a single filesystem. The disk drives and remote filesystems, located on fileservers, are mounted onto the filesystem and become part of a single filesystem. You can use the /etc/mount command to view the local drives and remote filesystems mounted on a computer with UNIX operating system.
How can you transfer files between two user accounts?---------You can use FTP from the UNIX command line to transfer files between two user accounts. You need to know the username and password of the other account, to which the file is to be transferred. The steps to be performed on the UNIX system to transfer files between two system are:
1. Enter ftp on the UNIX prompt.
2. Enter the username and password of the account to which the file is to be transferred.
3. Enter the put filename command to transfer file from your account to the second account and the get filename command to get files from the second account.
4. Enter the bye command to close the connection between the two accounts.
What is a Secure Shell?---------Secure Shell is a program that enables you to log into another computer over a network and execute commands over a remote computer. It also helps to move files from one computer to another. It provides strong authentication and secure communications over unsecured channels.
Is there any version of a Secure Shell available?--Yes, a Secure Shell is available in different versions. It has two versions, SSH1 and SSH2 that encrypt different parts of the packets. SSH1 uses server and host keys to authenticate systems whereas SSH2 uses only host keys.
What is the difference between write and talk commands?-------The write command copies the text from one user terminal to the terminal of another user who is also logged on the Unix operating system. The recipient can reply the sender by writing on his terminal and communication starts between the two users. The communication continues until an end-of-file is read from the terminal or an interrupt is sent.
The talk command is a visual communication program that copies lines from a user terminal to the terminal of another user. The talk command splits the user terminal into two sections. The upper section is used by the sender to write messages and the lower section displays the received messages.
How can a random number be generated using the shell script?--------The $RANDOM is an internal function of the bash shell that returns an integer in the range 0 - 32767. Following code generates five random numbers using the $RANDAM function.
#!/bin/bash
MAXCOUNT=5
count=1
echo
echo "$MAXCOUNT random numbers:"
while [ "$count" -le $MAXCOUNT ] # generates 5 ($MAXCOUNT) random integers.
do
number=$RANDOM
echo $number
let "count += 1" # increments count.
done
0 comments:
Post a Comment
Thanks For The Comment