Saturday, 16 May 2015

Unix Basics Interview Q&A's

1) What is meant by passwd file?
A) This file maintains each and every user information with 7 fields. The 7 fields are    Username:passwd:uid:gid:fullname:home:shell.
  
2) What is Shell?
A) Shell is a command line interpreter. Shell acts as an  interface between user and the kernel.

3) What is Kernel?
A) Kernel is core part of unix o/s. It is a group of hundreds of system calls.

4) What are different flavours of unix o/s?
A) Any operating system designed based on unix kernel called as flavour of unix. The following  are some flavours of unix
Linux ---- Red Hat
Sun solaris --- Sun Microsystem
IBM-AIX ----- IBM
Hp-ux ----- HP
Sco-unix ----- santa crus operations
IRIX------ Silicon Graphics.

5) What are the different security features in Unix?

            1. Password protection.
            2. File permissions.
            3. Encryption.

6) What’s the command to find out today’s date?
A)  date

7) What’s the command to find out users on the system?
 A) who

8) How do you find out the current directory you’re in?
A) pwd

9) What is the command to see the location of command?
A) Whereis  <commandname>

10) How do you find out your own username? 
A) Whoami    (or)  logname

11) How to close the current user account?
A) exit

12) How to create empty file?
A) Touch <filename>

13) How do you remove a file?
 A) Rm <filename>

14) How to join multifile files vertically?
A) Cat   file1  file2  file3 ……

15) The file for which we do not have write permission can be deleted using the command?
A) rm -f  <filename>

16) How do you remove a directory and its subdirectories ?
 A) rm –rf <directoryname>

17) How to rename a file?
A) Mv <filename>

18) How to copy multiple files and directories into some other directory?
A) cp -r source_directory destination_directory

19) How to see hidden files?
A) Ls –a

20) How to see files and subdirectories files recursively?
A) Ls –R

21) How to see files in long list format page wise?
A) Ls –l | more

22) How to identify whether a file is normal file or directory?
A) $ls -l filename/directoryname
if the first digit is - then it is file,
if it is d then it is directory file

23) What is the difference between "ls -r" and "ls -R"?

A) ls -r lists the files in reverse alphabetical order... whereas ls -R lists the files and directories recursively

24) The difference between a soft link and a hard link?
A) A symbolic (soft) linked file and the targeted file can be located on the same or different file   system while for a hard link they must be located on the same file system.

25) what are the different commands used to create files?
A) 1.touch - to create empty files (e.g) - touch <filename>
2.vi <filename>
3. cat>filename

26) List some wild card characters?
? -à Iit matches any single character
* -à It matches zero or more characters
[] -à It matches any single character in given list
. -à It matches any single character except enter key character

27) what is the output of the follwing command : ls [a-mno-r]*

A) list all the files in the current directory starting alphabet
    is between a to m  or n or between o to r
28) How do you count words, lines and characters in a file?
 A)  Wc <filename>

29) which command is used to identify the type of the file?
  A) file

30) "grep" means
A) Globally search a regular expression and print it

31) How do you search for a string inside a given file?
 A) grep string filename

32) How do you search for a string inside a  current directory?
 A) grep string *

33) How do you search for a string in a directory with the subdirectories recursed?
A)    grep -r string *

34) 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.


35) What are line patterns?
^ -à start of the line
$ -à End of the line

36) How to search empty lines in a given file?
A) Grep “^$” <filename>

37) How to count no of blank lines in a file?
A) Grep –c “^$” <filename>

38) How to remove Empty lines form a given file?
Grep –v “^$”  filename > temfilename
Mv  tempfilename  filename
39) What is pattern to search 4 digit word in a file?
A) Grep “\<[0-9] [0-9] [0-9] [0-9]\>” filename

40) What is pattern to search the line having only three characters?
A) Grep “^…$” filename

41) What is pattern to display lines ending with “$” character in a given file?
A) Grep “\$$” filename

42) How to display 2 and 4 th fileds from a given file if the delimetr is “:”?
A) Cut –d”:” –f 2,4 filename

43) How to display unique lines from a given file?
A) Sort –u filename

44) How to eliminate completely duplicate lines from a given file?
A) Uniq –u filename

45) How to remove all duplicate lines from a file?
Uniq –u filename > tempfilename
Mv  tempfilename  filename
46) How to delete “hello” word from a given file?
A) Sed “s/hello//” filename

47)How to compare two files are same or not?
A) Cmp

48) How to display the first 10 lines from a file?
A) Head  -10  filename

49) Write a one line command to convert all the capital letters of a file "test" into lower case?
A) cat filename | tr "[A-Z]"  "[a-z]"

50) The pipeline to list the five largest files in the current directory is

A)    ls -l | tr -s ' ' | sort -t ' ' -fnr +4 -5 | head –5

51) The pipeline to find out the number of times the character ? occurs in the file is
 A) tr -dc '?' < file | wc -c   ( Delete all the characters except ? and then make a word count.)

52) How to count total no. of users working in the system?
A) Who | wc –l

53) How to display the lines from 5 to 10 from a given file?
A) Head -10 filename | tail +5

54) what will be output of following command?
echo “Tecnosoft” | wc –c
A)    9

55) What is the default umask?
A) 022

56) What is the default permission for File & Directory ?
The Default privileges for file : 644
The default privileges for directory :  755

57) What UNIX command will control the default file permissions when files are created?
A) Umask

58) Explain the read, write, and execute permissions on a UNIX directory.

Read allows you to see and list the directory contents.

Write allows you to create, edit and delete files and subdirectories in the directory.

Execute gives you the previous read/write permissions plus allows you to change into the directory and execute programs or shells from the directory.

58) What is chmod, chown and chgrp?
Chmod : It is used for to change permissions on files
Chown : It is used for to change ownership of a file
Chgrp : It is used for to change group of the file

59) If the owner doesn’t have write permission on a file, but his/her group has, can he/she edit it?
A) No. He/she can’t, because the owner's permission overrides the group's.

60) To see list of files and directories ,what permission required?
A) Read permission

61) What are PIDs?
A) They are process IDs given to processes. A PID can vary from 0 to 65535.

62) How do you list currently running process?
 A) ps

63) How do you stop a background process?
 A) kill pid

64) How do you find out about all running processes?
 A) ps -ag

65) How do you stop all the processes, except the shell window?
 A) kill 0

66) How do you fire a process in the background?
 A) ./process-name &

67) What does the command "kill -9 $! " do?
A) kills the last background process

68) if there is a process u want to run even after exiting the shell what is the
command used?
A) Nohup

69) which command will get executed even after you log out?
 A) Nohup

70) which signal cannot be trapped?
A) kill –9

71) How to redirect standard error to a file? Answer
A) 2> filename

72) What does the top command display?
Top command displays the current amount of memory occupied 
by the currently executing processes and the details. In addition to memory usage top  command displays CPU usage and process details

73) What is the command to send message to all users who are logged in?
A) Wall

74) What is the command to send mail to other user?
A) Mail username

75) How to open secondary mail box?
A) Mail -f

76) What do you do if you don't want to be interrupted by other users' messages?
A) mesg n

No comments:

Post a Comment