Thursday, October 14, 2010

UNIX INTERVIEW QUESTIONS PART3


1) when we copy one directory to another directory,does the hidden files also get copied ?
ANS:-No
2)How to list the attributes of the current directory ?
ANS:- ls -ld .
3.) How hidden files are removed ?
ANS:- rm .[!.]*
4.)Can the filename contain / character?
ANS:- No
5)What is the limit on the length of the filename in unix ?
ANS:- 255 characters
6)cat file1 > /dev/null What is the size of /dev/null file after above command is executed successfully ?
ANS:- 0 bytes
7)How to acces the positional parameters having position greater than 9 ?
ANS:- using shift operator
8)ln file1 file2 will the exit status of the command cp file1 file2 be zero ?
ANS:- No
9)wc < chap[1-5] ?
ANS:- above command will be executed successfully if only one file matches the pattern else it will give error
10)the commands for which the executable is not executed are called……..
ANS:- Internal commands like echo,more
11) if u want to change in sccs ,which command do u use ?
ANS:- delta
12)what is the default permission for file and directory ?
ANS:- 666 and 777
13) write 3 commands for quit with saving the information in vi editor ?
ANS:- wq,:x (Esc mode) ZZ(command mode)
14.) abbr command is used for ?
ANS:- for creating macros in vi
15) If only wx permission is given to the directory then…………
ANS:- everything is possible except the listing of files.
16) what is the o/p of $ >xxx ?
ANS:- creates a 0 byte file called xxx
17) what is the result of $ ln file1 file2 ; cp file1 file2 dir1
ANS:- It will create these 2 new files file1,file2 in the directory dir1 & not new links
18)what is the o/p for $ mv file1* ..
ANS:- all files having names starting with file1 are moved to parent directory.
19. what will cat foo foo foo display?
20. to append .c to a variable x, you have to use
a.) echo $x.c
b.) echo $x”.c”
c.)echo ${x}.c
d.) none of these
e.) any of these
21. if TERM has the value vt220, where will you expect to find its control file?
22. find out the no. of words in this string as interpreted by a) vi and b) wc:
29.02.2000 is_last_day_of_febuary”
5. $a = 5
b=a
echo $b
what this will display?
23.what is the output of the follwing command : ls [a-mno-r]*
ANS:- list all the files in the current directory where starting alphabet is between a to m inclusive or m or between o to r
24.what is the mkdir -p option used for
mkdir -p dirpath creates all the directories in the path which do not exist.
25.what are the minimum number of links directory can have
ANS:-2
26.How are the devices treated in Unix
ANS:- files
27. what does(-)before the permissions of file in long listing signify
ANS:- ordinary files
28. Can an alias be exported to the subshells?
ANS:- No. An alias is local only to the shell in which it was declared and is lost once you logout.
29. What are the different security features in Unix?
ANS:-
1. Password protection.
2. File permissions.
3. Encryption.
30. Write a one line command to convert all the capital letters of a file “test” into lower case?
ANS:- dd if=test of=temp conv=lcase && cat temp
31) What are the commands used to control the flow of commands when they are given in a single line
1. $ &&
command2 is executed only after command1 is executed.
2. $ ||
command2 is executed independently without depending on the result of the first command
32. Write the output of the following commands ?
1. echo `this is a new file $1`
ksh: this: not found
2. echo ‘this is a new file $1′
this is a new file $1
3. echo “this is a new file $1″
this is a new file
$ set how r u my friend
4. echo “this is a new file $1″
this is a new file how
32)what is the output of the following command : echo \***
ANS:- ***
33) the contents of a file named file1 are as follows
a
ab
aab
b
b
1)what is the output of the follwing command : grep a* file1
ANS:-
a
ab
aab
2)what is the output of the following command : grep “a*” file1
ANS:-
a
ab
aab
b
b
3)what is the output of the following command : ls *
ANS:- it gives the all the files that are there in the directories and sub directories(not in the sub sub directories)
4)can a user modify the contents of a file if the sticky bit is on for the directory in which the file resides
ANS:- no
5)what is mkdir -m command used for ?
mkdir -m 777 newdir :assigns the rwx permissions to all irrespective of the umask value.
6)Given a pid how can I tell if its a running program using the kil command?
kill -0 PID
no message at the output implies that a process exists with the given PID, and therfore the system allows you to send signals to it.
7)what does ctrl-z do to a running process
the process is stopped.
8)what is the mkdir -p option used for
mkdir -p dirpath creates all the directories in the path which do not exist.
9)can a directory have more than 2 links
yes
10)what happens in case a command in a group of commands given at the shell prompt fails?
a) it continues with executing the rest of the commands
b) stops executing .
ANS:-b
34). What will the output be for the following commands:
a. $ tr –s str1
b. $ tr –s str1 str1
i. command a. gives error and command
b gives output same as the input
ii. command a. removes (deletes) all
occurrences of str1 and command b
gives output same as the input
iii. command a. gives error and
command b. replaces multiple
occurrences of str1 by single str1
iv. both command a. and command b.
replace multiple occurrences of str1 by single str1
35. What does the following command do:
cat file1 | grep ‘\\$$’
i. searches for \i\n file1
ii. searches for \$$ in file1
iii. looks for pattern: \ where is the process-id of the running process
iv. displays lines the end with \$
36. What does the following command do:
ps | grep sleep | cut -d ‘ ‘ -f 1 | kill -9
i. error
ii. it kills only the first ‘sleep’ process on the ps output
iii. it kills all the ‘sleep’ processes run by the user
37. For a user with login as ‘trainee1’ and member of group ‘grp_trng’, what will the output of following be:
echo $HOME
i. HOME
ii. /home/trainee1
iii. /home/grp_trng
iv. whatever the administrator has set the home directory of the user to be
38. What is ‘make’ used for?
i. To compile related files of a project
ii. To determine file dependencies for a project
iii. To get missing files from SCCS
iv. To execute a project executable
ANS:-: 1(iv) 2(iv) 3(i) 4(iv) 5(i)
39) What will be the output of the following code:
i=4 j=-1 k=0
[ $i -o $j -o $k ]
echo $?
[ $i -a $j -a $k ]
echo $?
[ $i -a $j -o $k ]
echo $?
ANS:-
0
0
0
40) What will be the output of the following code:
i=4 z=12
if [ $i = 5 -o $z -gt 50 ]
then
echo Sonata
else
echo Sonnette
fi
ANS:- Sonnette
41) What will be the output of the following code:
a=”*”
b=a
echo $b
a
42) What will be the output of the following code:
a=”*”
echo $a
echo “$a”
1st echo List all files / sub-directories in current directory
2nd echo displays *
43) Point out the errors if any:
x=10 y=15
if [ $x % 2 -eq $y % 3 ]
then
echo Barnie
fi
ANS:- Error in “if [ $x % 2 -eq $y % 3 ]“. Arithmetic computations require expr
44) Point out the errors if any:
x=10 y=15
if [ `expr $x % 2` = `expr $y % 3` ]
then
echo “\nCarpathians”
fi
ANS:- <---- Blank Line Carpathians
45) Point out error if any
message=happy holi
ANS:-: It gives an error
ksh: holi: not found
46) On executing set -3 +1
a. $1 would be -3
b. $1 would be -
c. $1 would be set
d. This command would result in an error
ANS:- This command results in an error “unknown option”
47) How will you find the number of files present in current directory without using wc command?
ANS:- set * echo $# gives no. of files in current directory.
48) What will be the output of the following statements? set Only God is in a position to look down upon someone.
echo $10 $11 $*
ANS:- Only0 Only1 Only God is in a position to look down upon someone.
49. UNIX can be best described as
a) Single user-single processing system
b) Single user-multi processing system
c) Multi user-single processing system
d) Multi user-multi processing system
50. Kernal refers to inode by index from
a) Super block
b) Boot block
c) Data block
d) None of the above.
51. Which is not a SCCS command?
a) Admin
b) get
c) ps
d) none
52) Which is the correct sequence of a program sequence (C) ?
a) EDIT,PREPROCESS,COMPILE,LOAD,LINK,EXECUTE
b) EDIT,PREPROCESS,COMPILE,LINK,LOAD,EXECUTE
c) EDIT,COMPILE,PREPROCESS,LINK,LOAD,EXECUTE
d) EDIT,PREPROCESS,LINK,COMPILE,LOAD,EXECUTE
53.Which of the following permission can be attached in UNIX environment
a) read only
b) hidden
c) archievly
d) none
54) The inode list in the disk consists of
(a) file owner identifier
(b) file type
(c) file access permissions
(d) All the above
55) WC command gives filename also along with count. How to supress it?
ANS:- give standard input symbol before filename.
56)The other way of running shell script apart from using sh command and chmod?
ANS:- using ! we can run a shell script
57) As far as SCCS concerned which is false?
a) It is used to keep track of dependency b/w files
b) It just maintains difference b/w versions of various files.
c) it works in conjuction with MAKE.
d) It is mainly used for configuration management.
58:) How can you kill the last job run in background without using the ps command
ANS:- To kill the last background job the following command is used:
$ kill $! The system variable $! stores the PID of the last background job.
The other method is first find the PID using the ps command then use kill command to do the job.
59)What is the outcome of $mkdir -p dir/dir1/dir2/dir3
ANS:- it will create a rooted directory with one inside the other.
60)what is the output of $(date) | tee save | wc
ANS:- it will output the actual count of words in date to both output and file save.
61)what is the diff between $echo hello world > file $> file echo hello world
ANS:- it is the same.
62) what is the difference between $(var-item) $(var=item)
ANS:-: the first will make the var display the value item in the following command if var
is undefined.the second will assign the value item to var if var is undefined.
63)What is the output of the following commands:
b=a
a=c
$echo $$a
$echo $$$a
ANS:-: Assume PID is 6008
then output is:
6008a
6008c
63)What is the ideal umask for directory?
ANS:-023
63)What is the size of i-node entry in i-node table?
ANS:-64 bytes
65)How do you reverse the background colour for session display?
ANS:-tput rev;
66)What would be the output of foll statement:
set We work at Infy echo $0
ANS:- -ksh
67)State true or false :Unix supports multiple file systems.
ANS:-True
68. what is the ‘at’ command?
the ‘at’ command is used to schedule tasks at a later date.at takes as its argument the
time the job
is to be executed. The command uses standard input to accept the script names that
need to be executed
$ at 14:05
prog1.sh
$at 5pm < prog2.sh >output
69. what is the “here” document?
The here document represents the fourth source of the standard input. Denoted by <<
.followed by a delimiter.The shell treats every line following the command and delimited
by the string
as input the command. The accompanying text following the here symbol is also part of
the command line.
It is especially useful when used with commands which dont accept the input filename
as an argument.
70. what is an i-node?
i-node is a 16-bit structure maintained in a special area of the disk for storing the
attributes of the file.
The table contains the file permissions, ownership details as well as the number of
links of the file.
71. Difference between grep, egrep and fgrep
grep : does not accept more then one expression
egrep : accepts more than one pattern for search.Also accepts patterns from a file.
fgrep : accepts multiple patterns both from command line and file but does not accept
regular expressions only strings.
It is faster than the other two and should be used when using fixed strings.
72. what is the output of the following ?
$echo *\ *
* *
$echo *\*
**
$echo * \*
list of all the files in current directory + *
$echo ‘* \*’
* \*
73. Difference between halt command and shutdown command
Halt command can be invoked by normal users to halt the system. This command in
turn invokes Shutdown command.
Shutdown command can be invoked only by the superuser.
74. What would be the output of the following command?
$> >>xxtty
ANS:- Create a new blank file xxtty
75) What would be the output of &> >> junk echo hello where junk is existing file.
ANS:- append hello to file junk
76) What is the use of -m and -p options in mkdir command?
ANS:- -m option directly sets the directory permission.
eg. mkdir -m 754 dirname
# sets the permission independent of
system wide default permission
-p option creates multiple directories ina single go.
eg. mkdir -p a/b/c
77) What would be the difference between $> echo \\\\n and $> echo \\\\\n
ANS:-Both of them print \n
78) Using grep, find blank line in a file.
ANS:- grep ‘^$’ filename
79) Search either [ or ]
ANS:- grep ‘[][]‘ filename
80) what is the output for $> echo $_
ANS:- It will display the last argument of last executed command.
81) What does the purpose of $> set -v
ANS:- This command causes shell to echo each command before it executes it.It can
be used while debugging a shell program by inserting the statement as the first
statement of the program.
82) How to read from a file line by line in a script?
ANS:-The shell script follows:
terminal=`tty`
exec < filename
while read line
do
echo $line
done
exec < $terminal
Here the exec statement is used to redirect the standard input from a file so that the
read statement reads file line by line and returns failure at the end of file. the last
statement again makes the read statement to read from keyboard.


Print this post

No comments: