Set - 6

Question 1 :

Explain the following commands.

Answer :

$ ls > file1
$ banner hi-fi > message
$ cat par.3 par.4 par.5 >> report
$ cat file1>file1
$ date ; who
$ date ; who > logfile
$ (date ; who) > logfile

Question 2 :

What is the significance of the "tee" command?

Answer :

It reads the standard input and sends it to the standard output while redirecting a copy of what it has read to the file specified by the user.

Question 3 :

What does the command " $who | sort –logfile > newfile" do?

Answer :

The input from a pipe can be combined with the input from a file . The trick is to use the special symbol "-" (a hyphen) for those commands that recognize the hyphen as std input.
In the above command the output from who becomes the std input to sort , meanwhile sort opens the file logfile, the contents of this file is sorted together with the output of who (rep by the hyphen) and the sorted output is redirected to the file newfile.

Question 4 :

What does the command "$ls | wc –l > file1" do?

Answer :

ls becomes the input to wc which counts the number of lines it receives as input and instead of displaying this count , the value is stored in file1.

Question 5 :

Which of the following commands is not a filter man , (b) cat , (c) pg , (d) head

Answer :

man A filter is a program which can receive a flow of data from std input, process (or filter) it and send the result to the std output.

Question 6 :

How is the command "$cat file2 " different from "$cat >file2 and >> redirection operators ?

Answer :

is the output redirection operator when used it overwrites while >> operator appends into the file.

Question 7 :

Explain the steps that a shell follows while processing a command.

Answer :

After the command line is terminated by the key, the shell goes ahead with processing the command line in one or more passes. The sequence is well defined and assumes the following order.
Parsing: The shell first breaks up the command line into words, using spaces and the delimiters, unless quoted. All consecutive occurrences of a space or tab are replaced here with a single space.
Variable evaluation: All words preceded by a $ are valuated as variables, unless quoted or escaped.
Command substitution: Any command surrounded by back quotes is executed by the shell which then replaces the standard output of the command into the command line.
Wild-card interpretation: The shell finally scans the command line for wild-cards (the characters *, ?, [, ]).
Any word containing a wild-card is replaced by a sorted list of
filenames that match the pattern. The list of these filenames then forms the arguments to the command.
PATH evaluation: It finally looks for the PATH variable to determine the sequence of directories it has to search in order to hunt for the command.

Question 8 :

What difference between cmp and diff commands?

Answer :

cmp - Compares two files byte by byte and displays the first mismatch diff - tells the changes to be made to make the files identical

Question 9 :

What is the use of 'grep' command?

Answer :

'grep' is a pattern search command. It searches for the pattern, specified in the command line with appropriate option, in a file(s).
Syntax : grep
Example : grep 99mx mcafile

Question 10 :

What is the difference between cat and more command?

Answer :

Cat displays file contents. If the file is large the contents scroll off the screen before we view it. So command 'more' is like a pager which displays the contents page by page.

Question 11 :

Write a command to kill the last background job?

Answer :

Kill $!

Question 12 :

Which command is used to delete all files in the current directory and all its sub-directories?

Answer :

rm -r *

Question 13 :

Write a command to display a file's contents in various formats?

Answer :

$od -cbd file_name
c - character, b - binary (octal), d-decimal, od=Octal Dump.

Question 14 :

What will the following command do?

Answer :

$ echo *
It is similar to 'ls' command and displays all the files in the current directory.

Question 15 :

Is it possible to create new a file system in UNIX?

Answer :

Yes, 'mkfs' is used to create a new file system.