One of the most powerful multi-user operating systems, UNIX is still very famous today. It is used in environments that need maximum reliability. Whether you are looking for a position that entails basic UNIX commands or the one that needs you to write a code, UNIX helps you grow in your professional sphere. If you are confident to make a move in your career, prepare for UNIX interview questions and answers. Get, Set, Go!
Here is the list of most frequently asked Unix Interview Questions and Answers:
Below is the list of most frequently asked Unix interview questions which one prepare for the upcoming interview round:
Q1. How can you create an archive file?
Ans. It can be created by using the tar command.
Q2. How to debug the bash script?
Ans. Simply add –xv to #! /bin/bash
Q3. What is the difference between Linux and UNIX?
- It is not flexible like Linux
- UNIX is not free
- UNIX systems are categorized into various flavors, developed by commercial vendors and non-profit organizations
- It can be freely distributed through magazines, books, etc.
- Linux is compatible with most hardware systems
- It is highly scalable and supports a large set of file systems
Q4. Give an example of how to write a function?
Echo “Hi everyone!”
Q5. What is the difference between cmp and diff commands?
Ans. Cmp is used for binary files, whereas diff is used for files in text format.
Q6. Define paging?
Ans. It is a memory management system by which a computer stores and retrieves data from secondary storage.
Q7. Which command is used to kill the last background job?
Ans. Kill $!
Q8. Define shell?
Ans. It is an environment in which we can run shell scripts, commands, and programs. There are two types of shells:
- The Bourne shell
- The C shell
Q9. Which command is used to remove the seventh line from a file?
Ans. sed -i ‘7 d’ test.txt
Q10. Is UNIX open source?
Also Read>> Top Most Paying Technology Certifications!
Q11. Define a hidden file?
Ans. A file starting with a dot is known as a hidden one.
Q12. What are the links?
Ans. A link is a pointer to a file. It can be used to assign more than one name to a file, but can’t be used to assign a directory on various computers.
Q13. Which programming language is used for UNIX?
Q14. Which command is used to change the password?
Q15. Which switch is used in test expression to determine a file as a regular file?
Q16. Name some system calls used for process management?
Q17. Which command will be used to change the protection mode of files beginning with the string emp and finishing with 1 or 2?
Ans. chmod u+x emp[1-3]
Q18. What is the use of the tee command?
Ans. Tee command is used for sending data from the standard point.
Q19. What are directory navigation tools?
Ans. Directory navigation tools are performed on directories. For example:
Q20. How can you remove a file in UNIX?
Ans. By using rm command.
Q21. Define Kernel?
Ans. The basic center of a computer operating system, it is the kernel job to regulate to access the system hardware.
Q22. What are the main responsibilities of a shell?
- Filename and variable substitution
- Integrated programming language
- Pipeline hookup
- Input/output redirection
- Environment control
Q23. What are the five variants of Linux?
Q24. What data structures are used for Demand paging?
- Disk block descriptors
- Page table entries
- Swap-use table
- Page frame data table
Q25. What is ‘filters’?
Ans. In Unix, there are a number of Filters which are known as the programs for taking plain text. These plain texts are either stored in files or are produced by some other program. Further, these programs are transformed into a particular format that is designed to return standard outputs.
Some of the most popular filters are:
|head||head [-number_of_lines_to_print] [path]|
|tail||tail [-number_of_lines_to_print] [path]|
|sort||sort [-options] [path]|
|uniq||uniq [options] [path]|
|wc||wc [-options] [path]|
|grep||grep [options] pattern [path]|
|nl||nl [-options] [path]|
Q26. What is the grep command?
Ans. GREP or Global Regular Expression Print is a Unix/Linux command-line tool that is used to locate a string of characters in a given file. Here the text search pattern is known as the regular expressions and as the tool finds the match, it prints the line. Further, this tool is compatible with large log files. Below is the method to use the grep command in Unix:
Grep Syntax – grep [options] pattern [files]
Q27. State the description of the following commands.
|-c||Prints only lines which is the exact match of the pattern|
|-i||The matching case is ignored|
|-l||Displays a list of filenames only|
|-f file||Considers file patterns one from each line|
|-o||Prints the matched parts in the matching line|
Q28. How to display the number of lines before or after a search string?
Ans. By adding the following operators to the desired lines before or after can help:
|Print three lines after the match||grep –A 3 phoenix sample|
|Print two lines before the match||grep –A 2 phoenix sample|
|Print two lines before and after the match||grep –C 2 phoenix sample|
Q29. When to use -w option?
Ans. The -w option is used when one wants to search for a word and avoid it to match the substring. For example, if you want to search the word ‘to’ so the common result that you would get could be:
“To”, stool, too, tools, top, customer, automatic, etc. Thus the option -w helps.
Q30. Define inode.
Ans. An inode is a unique entry which by default gets created on a disk section for a file system. It contains the following information:
- Location on the disk where the file starts
- User ID of the file
- Size of the file
- Group ID of the file
- Device ID
- File size
- Date of creation
- Owner of the file
- File protection flag
- Link counter
Q31. What are shell variables?
Ans. A variable refers to the character string to which a value is assigned and a shell enables the process of creating, assigning, and deleting variables. In Unix, the shell variables are denoted in uppercase. There are three main types of variables which are present in the shell:
- Local variables
- Environment variables
- Shell variables
Syntax to define variable → variable_name=variable_value
Q32. Define a Zombie process in UNIX.
Ans. A process is called a Zombie process when it has completed the execution stage (is dead) however, its entry has not vanished. Such entries are still visible in the process table. Usually, a situation like this generally arises when the child completes the process before the parent. Thus the child remains in the zombie state considering the fact that the parent might sometimes need the child even if the child’s execution has already happened.
Q33. What is the Orphan process?
Ans. An orphan process is determined as the process which is still in the execution stage however its parents have died. Once the parents die, init adopts the newly turned orphaned child process. The orphan process may occur intentionally or unintentionally. The intentional orphan process has no support when it runs in the background. However, the unintentional orphan process initiates when the process crashes or terminates.
Q34. State the meaning of following Debug Statement Options.
|Debug Statement Options||Meaning|
|set -x||Print the statement once the interpretation of metacharacters and variables is finished|
|set -v||Print the statement before interpreting metacharacters and variables is finished|
|set +x||Stop statement printing|
Q35. What do you know about Until Loop?
Ans. Unlike the While loop, Until loop performs as long as the command fails, and once the command succeeds, the loop exits. Here is the syntax for:
Q36. Name some of the popular metacharacters (shell special characters)?
Ans. Below are some of the popular special characters used in Unix/Linux:
* ? [ ] ‘ ” \ $ ; & ( ) | ^ < > new-line space tab
Q37. In Unix, how can you change Owners and Groups?
Ans. The following two commands help in changing ‘Owners and Groups’:
- chown − To “change owner” – $ chown user filelist
- chgrp − – $ chgrp group filelist (To “change group”)
Q38. Why does the command ‘cat’ basically do?
Ans. Cat command is used to create files (single or multiple), view contents of file, concatenate files or texts, and redirect output to files or terminal
cat [OPTION] [FILE]…
|Display Contents of File||# cat /etc/passwd/|
|View Contents of Multiple Files in terminal||# cat test test1|
|Create a File||# cat >test2|
These UNIX interview questions and answers will be helpful for a quick look before appearing for the interview. If someone wants to improve his/her skills, take the UNIX training course available online.
If you have recently completed a professional course/certification, click here to submit a review and get FREE certification highlighter worth Rs. 500.