UNIX Commands : Placement Preparations



hi friends these are some faq's on unix commands as per collected from various years and companies papers . hope this will you in your preparations..


1. What is relative path and absolute path.
Absolute path : Exact path from root directory.
Relative path : Relative to the current path.
2. Explain kill()and its possible return values.
There are four possible results from this call:
· ‗kill()‘ returns 0. This implies that a process exists with the given PID, and the system would allow you to send signals to it. It is system-dependent whether the process could be a zombie.
· ‗kill()‘ returns -1, ‗errno == ESRCH‘ either no process exists with the given PID, or security enhancements are causing the system to deny its existence. (On some systems, the process could be a zombie.)
· ‗kill()‘ returns -1, ‗errno == EPERM‘ the system would not allow you to kill the specified process. This means that either the process exists (again, it could be a zombie) or draconian security enhancements are present (e.g. your process is not allowed to send signals to *anybody*).
· ‗kill()‘ returns -1, with some other value of ‗errno‘ you are in trouble! The most-used technique is to assume that success or failure with ‗EPERM‘ implies that the process exists, and any other error implies that it doesn't.
An alternative exists, if you are writing specifically for a system (or all those systems) that provide a ‗/proc‘ filesystem: checking for the existence of ‗/proc/PID‘ may work.
3. What is a pipe and give an example?
A pipe is two or more commands separated by pipe char '|'. That tells the shell to arrange for the output of the preceding command to be passed as input to the following command.
Example : ls -l | pr
The output for a command ls is the standard input of pr.
When a sequence of commands are combined using pipe, then it is called pipeline.
4. How to terminate a process which is running and the specialty on command kill 0?
With the help of kill command we can terminate the process.
Syntax: kill pid
Kill 0 - kills all processes in your system except the login shell.
5. What is redirection?
Directing the flow of data to the file or from the file for input or output.
Example : ls > wc
6. What are shell variables?
Shell variables are special variables, a name-value pair created and maintained by the shell.
Example: PATH, HOME, MAIL and TERM
7. How to switch to a super user status to gain privileges?
Use ‗su‘ command. The system asks for password and when valid entry is made the user gains super user (admin) privileges.
8. How does the kernel differentiate device files and ordinary files?
Kernel checks 'type' field in the file's inode structure.
9. What is the significance of '&' at the end of any command?
To make the process run as a background process.
10. How many prompts are available in a UNIX system?
Two prompts, PS1 (Primary Prompt), PS2 (Secondary Prompt).
11. Name the data structure used to maintain file identification?
‗inode‘, each file has a separate inode and a unique inode number.
12. What is the purpose of 'ps' command and its columns?
· To display process status of all the processes currently running in the system.
· Columns include UID, PID, PPID, STATUS, COMMAND, TTY and TIME.
· Various STATUS type are S - sleeping, R - Running, I - Intermediate.
13. Is it possible to count number char, line in a file; if so, How?
Yes, wc-stands for word count.
wc -c for counting number of characters in a file.
wc -l for counting lines in a file.
14. Is ‗du‘ a command? If so, what is its use?
Yes, it stands for ‗disk usage‘. With the help of this command you can find the disk capacity and free space of the disk.
15. What is the use of the command "ls -x chapter[1-5]"
ls stands for list; so it displays the list of the files that starts with 'chapter' with suffix '1' to '5', chapter1, chapter2, and so on.
16. Is it possible to restrict incoming message?
Yes, using the ‗mesg‘ command.
17. Is it possible to create new a file system in UNIX?
Yes, ‗mkfs‘ is used to create a new file system.
18. What will the following command do?
$ echo *
It is similar to 'ls' command and displays all the files in the current
directory.
19. What is the purpose of 'FINGER', 'NICE' and 'TOUCH' command?
FINGER : displays information about all the users logged in.
NICE : sets priority of a process range of the NICE value 0 - 39.
TOUCH : creates empty files as specified and can also be used to change a file's modified time without modifying the file.
20. What is the purpose of 'nohup' command?
A Set of processes are preceded by the command ‗nohup‘ along with a output file. Even if the user is logged off the process is not killed and the resulted is evaluated and stored in output file.
21. Write a command to display a file‘s contents in various formats?
$od -cbd file_name
c - character, b - binary (octal), d-decimal, od=Octal Dump.
22. Which command is used to delete all files in the current directory and all its sub-directories?
rm -r *
23. Write a command to kill the last background job?
Kill $!
24. What is the difference between cat and more command?
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.
25. What is the use of ‗grep‘ command?
‗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
26. What difference between cmp and diff commands?
cmp - Compares two files byte by byte and displays the first mismatch
diff - tells the changes to be made to make the files identical
27. Explain the steps that a shell follows while processing a command.
After the command line is terminated by the key, the shel 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 avaluated as variables, unless quoted or escaped.
Command substitution: Any command surrounded by backquotes 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.
28. What is the difference between > and >> redirection operators ?
> is the output redirection operator when used it overwrites while >> operator appends into the file.
29. How is the command ―$cat file2 ― different from ―$cat >file2 file1‖ do?
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.
32. What does the command ― $who | sort –logfile > newfile‖ do?
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.
33. What is the significance of the ―tee‖ command?
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.
34. Explain the command ―$who | tee file1 file2 /dev/tty3a | sort > file3‖
Store the output of who in file1, file2 ,display the same output on the screen store the sorted output int file3. /dev/tty3a is the file associated with the terminal.
Exercise :-
35. Explain the following commands.
$ 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
36. Construct pipes to execute the following jobs.
1. Output of who should be displayed on the screen with value of total number of users who have logged in displayed at the bottom of the list.
2. Output of ls should be displayed on the screen and from this output the lines containing the word ‗poem‘ should be counted and the count should be stored in a file.
3. Contents of file1 and file2 should be displayed on the screen and this output should be appended in a file .
4. From output of ls the lines containing ‗poem‘ should be displayed on the screen along with the count.
5. Name of cities should be accepted from the keyboard . This list should be combined with the list present in a file. This combined list should be sorted and the sorted list should be stored in a file ‗newcity‘.
6. All files present in a directory dir1 should be deleted any error while deleting should be stored in a file ‗errorlog‘.
Section II – SQL
1. Which is the subset of SQL commands used to manipulate Oracle Database structures, including tables?
Ans Data Definition Language (DDL)
2. What operator performs pattern matching?
Ans LIKE operator
3. What operator tests column for the absence of data?
Ans IS NULL operator
4. Which command executes the contents of a specified file?
Ans. START or @
5. What is the parameter substitution symbol used with INSERT INTO command?
Ans. &
6. Which command displays the SQL command in the SQL buffer, and then executes it?
Ans RUN
7. What are the wildcards used for pattern matching?
Ans` _ for single character substitution and % for multi-character substitution
8. State true or false. EXISTS, SOME, ANY are operators in SQL.
Ans True
9. State true or false. !=, <>, ^= all denote the same operation.
Ans. True
10. What are the privileges that can be granted on a table by a user to others?
Ans. Insert, update, delete, select, references, index, execute, alter, all
11. What command is used to get back the privileges offered by the GRANT command?
Ans REVOKE
12. Which system tables contain information on privileges granted and privileges obtained?
Ans USER_TAB_PRIVS_MADE, USER_TAB_PRIVS_RECD
13. Which system table contains information on constraints on all the tables created?
Ans USER_CONSTRAINTS
14. TRUNCATE TABLE EMP;
DELETE FROM EMP;
Will the outputs of the above two commands differ?
Ans Both will result in deleting all the rows in the table EMP.
15. What is the difference between TRUNCATE and DELETE commands?
Ans TRUNCATE is a DDL command whereas DELETE is a DML command. Hence DELETE operation can be rolled back, but TRUNCATE operation cannot be rolled back. WHERE clause can be used with DELETE and not with TRUNCATE.
16. What command is used to create a table by copying the structure of another table?
Ans CREATE TABLE .. AS SELECT command
Explanation :
To copy only the structure, the WHERE clause of the SELECT command should contain a FALSE statement as in the following.
CREATE TABLE NEWTABLE AS SELECT * FROM EXISTINGTABLE WHERE 1=2;
If the WHERE condition is true, then all the rows or rows satisfying the condition will be copied to the new table.
17. What will be the output of the following query?
SELECT REPLACE(TRANSLATE(LTRIM(RTRIM('!! ATHEN !!','!'), '!'), 'AN', '**'),'*','TROUBLE') FROM DUAL;
Ans
TROUBLETHETROUBLE
18. What will be the output of the following query?
SELECT DECODE(TRANSLATE('A','1234567890','1111111111'), '1','YES', 'NO' );
Ans NO
Explanation :
The query checks whether a given string is a numerical digit.
19. What does the following query do?
SELECT SAL + NVL(COMM,0) FROM EMP;
Ans
This displays the total salary of all employees. The null values in the commission column will be replaced by 0 and added to salary.
20. Which date function is used to find the difference between two dates?
Ans MONTHS_BETWEEN
21. Why does the following command give a compilation error?
DROP TABLE &TABLE_NAME;
Ans
Variable names should start with an alphabet. Here the table name starts with an '&' symbol.
22. What is the advantage of specifying WITH GRANT OPTION in the GRANT command?
Ans. The privileged receiver can further grant the privileges he/she has obtained from the owner to any other user.
23. What is the use of the DROP option in the ALTER TABLE command?
Ans It is used to drop constraints or any column specified on/in the table.
24. What is the value of ‗comm‘ and ‗sal‘ after executing the following query if the initial value of ‗sal‘ is 10000?
UPDATE EMP SET SAL = SAL + 1000, COMM = SAL*0.1;
Ans.
sal = 11000, comm = 1000
25. What is the use of DESC in SQL?
Ans
i. DESC equivalent to DESCRIBE
ii. DESC is Descending order
DESC has two purposes. It is used to describe a schema as well as to retrieve rows from table in descending order.
Explanation :
The query SELECT * FROM EMP ORDER BY ENAME DESC will display the output sorted on ENAME in descending order.
26. What is the use of CASCADE CONSTRAINTS?
Ans
When this clause is used with the DROP command, a parent table can be dropped even when a child table exists.
27. Which function is used to find the largest integer less than or equal to a specific value?
Ans FLOOR
28. What is the output of the following query?
SELECT TRUNC(1234.5678,-2) FROM DUAL;
Ans 1200




Reblog this post [with Zemanta]

0 comments:

Post a Comment