Top Unix Interview Questions and Answers for 2023
In this article, we will discuss top 45 questions that are asked in the interview that will help you to crack the interview.
Unix is one of the most powerful multi-user operating systems. It is a highly configurable, versatile, and multi-tasking system for servers, desktops, and laptops. Whether you are interviewing for a programming job that needs you to write a code or looking for a position that entails basic Unix commands, you must prepare yourself to answer Unix interview questions. This blog lists 40+ most frequently asked Unix interview questions that will help you crack your Unix interview and acquire your dream job.
Top Unix Interview Questions and Answers
Here is the list of the most commonly asked interview questions on Unix for 2022:
Best-suited IT & Software courses for you
Learn IT & Software with these high-rated online courses
Q1. What are the core components of Unix?
Ans. Unix consists of three components namely, kernel, shell, and file programs. They are explained below:
- Kernel – kernel is the lowest layer of the Unix operating system. Also known as the heart Unix, the kernel directly interacts with the computer hardware. It is responsible for allocating and managing the resources available to programs. It monitors major processes like memory management, file management, and task scheduling. It also offers an interface to programs where they can access files, the network, and devices.
- Shell – the shell is also called a command prompt. It is responsible for connecting the user to the operating system. The shell translated the user input into the language understood by the command prompt, and then the corresponding actions are performed.
- Programs – Unix has a variety of small programs to meet different needs. Each Unix program performs one thing. Due to the modular design, the functionality of small programs to be mixed and matched. This offers flexibility to the users, allowing them to accomplish almost any task. While programs operate on top of the shell, they may also interact directly with the kernel.
Also Explore:
Top Full Stack Development Courses | Popular Big Data Courses |
Top Programming Courses | Popular QA and Testing Courses |
Q2. How can you create an archive file?
Ans. It can be created by using the tar command.
Q3. How to debug the bash script?
Ans. Simply add –xv to #! /bin/bash
Q4. What is the difference between Linux and UNIX?
Ans. It is one of the most important Unix interview questions that you must prepare for your interview.
Linux is the clone of Unix and has some features similar to Unix. However, they do have some key differences as mentioned in the table below:
Linux | Unix |
Linux is free to use and open source | Unix is a licensed OS and is not open source |
It is used in desktops, servers, mainframes, and smartphones. | It is used on servers, workstations, and PCs. |
Bash (Bourne Again SHell) is the default shell. | Bourne Shell is the default shell. |
Supported file systems: Ext2, Ext3, Ext4, ReiserFS, Xfs, Jfs, Btrfs, FAT | Supported file systems: hfs, hfs+, fs, gpfs, ufs, xfs, zfs |
Different versions of Linux: Redhat, Ubuntu, OpenSuse | Different versions of Unix: HP-UX, AIS, BSD |
Q5. Give an example of how to write a function?
Ans. Example:
{
Echo “Hi everyone!”
}
Explore the popular Operating System Courses
Q6. 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.
Q7. Define paging.
Ans. It is a memory management system by which a computer stores and retrieves data from secondary storage.
Q8. Which command is used to kill the last background job?
Ans. Kill $!
Q9. 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
Q10. Which command is used to remove the seventh line from a file?
Ans. sed -i ‘7 d’ test.txt
Q11. Is UNIX open source?
Ans. No.
Q12. Define a hidden file?
Ans. A file starting with a dot is known as a hidden one.
Q13. 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.
Also explore:
- Paid and free online courses by Coursera
- Popular online Udemy courses
- Top online edX courses
Q14. Which programming language is used for UNIX?
Ans. C.
Q15. Which command is used to change the password?
Ans. Passwd.
Q16. Which switch is used in test expression to determine a file as a regular file?
Ans. -F
Q17. Name some system calls used for process management?
Ans. It is one of the most commonly asked Unix interview questions.
Process management uses several system calls. They are explained below:
Unix System calls for Process Management | Description |
fork() | create a new process |
exec() | execute a new program in a process |
wait() | wait until a created process completes its execution |
exit() | exit from a process execution |
brk() | increase/decrease the data segment size of a process |
getpid() | get a process identifier of the current process |
getppid() | get parent process identifier |
nice() | bias the existing priority of a process |
Q18. What are the Unix System calls for I/O?
Ans. A system call is a way through which programs interact with the operating system. Unix System calls are used for file management, process control, device management, information management, and communication. Below are some of the commonly used System calls for I/O:
Unix System calls for I/O | Description |
open(pathname,flag,mode) | open file |
close(filedes) | close an open file |
creat(pathname,mode) | create file |
write(filedes,buffer,bytes) | write data to an open file |
read(filedes,buffer,bytes) | read data from an open file |
lseek(filedes,offset,from) | position an open file |
dup(filedes) | duplicate an existing file descriptor |
dup2(oldfd,newfd) | duplicate to the desired file descriptor |
ioctl(filedes,request,arg) | change behavior of an open file |
fcntl(filedes,cmd,arg) | change properties of an open file |
Check out the best Online Emerging Technologies Courses
Q19. 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]
Q20. What is the use of the tee command?
Ans. Tee command is used for sending data from the standard point.
Q21. What are directory navigation tools?
Ans. Directory navigation tools are performed on directories. For example:
- rmdir
- mkdir
- pwd
- Is
- cd
Q22. How can you remove a file in UNIX?
Ans. By using rm command.
Eg:
%rm <filename>
Q23. Define Kernel?
Ans. The basic center of a computer operating system, it is the kernel job to regulate to access the system hardware.
Q24. What are the main responsibilities of a shell?
Ans.
- Filename and variable substitution
- Integrated programming language
- Pipeline hookup
- Input/output redirection
- Environment control
Explore the 7 Most In Demand Tech Skills
Q25. What are the five variants of Linux?
Ans.
- Debian
- Fedora
- Redhat
- Ubuntu
- Cent
Q26. What data structures are used for Demand paging?
Ans.
- Disk block descriptors
- Page table entries
- Swap-use table
- Page frame data table
Q27. 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:
Filter | Syntax |
cat | cat [path] |
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] |
tac | tac [path] |
sed | sed [path] |
nl | nl [-options] [path] |
Q28. 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]
Explore the Top 8 Highest Paying IT Certifications
Q29. State the description of the following commands.
Ans.
Options | Description |
-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 |
Q30. 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:
Action | Command |
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 |
Q31. 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.
Also Read: Top Udemy Courses – Technical Courses for IT Professionals
Q32. 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
- Permission
- Owner of the file
- File protection flag
- Link counter
Q33. 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 that are present in the shell:
- Local variables
- Environment variables
- Shell variables
Syntax to define variable → variable_name=variable_value
Q34. 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.
Q35. 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.
Also Read: Top Online IT Courses for IT Professionals
Q36. State the meaning of following Debug Statement Options.
Ans.
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 |
Q37. 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:
until control_command
do
statement1
…
statementN
Done
Q38. 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
Q39. 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”)
Q40. 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]…
Function | Command |
Display Contents of File | # cat /etc/passwd/ |
View Contents of Multiple Files in terminal | # cat test test1 |
Create a File | # cat >test2 |
Q41. What is a Process in Unix?
Ans. It is one of the frequently asked Unix interview questions.
A process is a sequence of instructions or an instance of the program that is being executed. Any program executed creates a process. Processes can be manipulated similar to how files can be manipulated.
Process attributes: A process has several properties associated with it:
- PID: Process-ID
- PPID: Parent Process Id
- TTY: Terminal with which the process is associated
- UID: User Id
Process Control Commands: Many commands are available to review and manipulate processes. Some of them are listed below:
Command | Description |
ps | gives information of all the processes currently running for a user |
kill | terminates running processes |
bg | resumes suspended process while keeping them running in the background |
fg | Resumes a program that was stopped and bring it to the foreground |
ps PID | gives status of a particular process |
pidof | gives Process ID of a process |
Q42. What is the command to view your username in Unix?
Ans. The whoami command is used in Unix Operating System to display the username of the currently logged-in user. It is the concatenation of the strings ‘who’, ‘am’, ’I’.
Syntax:
%whoami
Q43. What is the difference between multiuser and multi-task?
Ans. Multiuser is when more than one person can use the computer at the same time. Multitask is when a single user can use the computer for more than one task at the same time.
Q44. Explain piping.
Ans. In Linux, piping is a form of redirection. It is used to send the output of one command or program or process to another command or program or process for further processing. The symbol ‘|’ is used to denote a pipe.
The syntax for the pipe command:
Command-1 | Command-2 | …| Command-N |
Q45. What are the Permissions and User grants available for Unix file system/users?
Ans. There are three access level permissions associated with each file:
- User permission: level of access given to the user matching the file’s UID.
- Group permission: level of access given to users in groups matching the file’s GID.
- Others permission: level of access given to users without a matching UID or GID.
From a File point of view, a user will have three access rights:
- Read: The user can read the contents of the file. (denoted by r)
- Write: The user can modify the contents of the file. (denoted by w)
- Execute: The user can execute the files. (represented by x)
We can view the permissions associated with each file in the current folder using the ls -l command.
Q46. What is a single-user system?
A single-user system refers to a computer system or software designed to be used by only one individual at a time. In a single-user system, the resources of the system, such as the CPU (Central Processing Unit), memory, and storage, are dedicated to serving the needs of a single user.
Conclusion
There is a great demand for Unix professionals in software technology. Unix helps you grow professionally and allows you to choose from various career paths like a Unix Engineer, Administrator, Systems Engineer, and Analyst Engineer in Unix.
We hope you enjoyed this Unix interview questions and answers blog. These questions would help beginners and experienced candidates to crack their Unix interview on the first attempt.
FAQs
What is the difference between cmp and diff commands?
Cmp is used for binary files, whereas diff is used for files in text format.
Define paging.
It is a memory management system by which a computer stores and retrieves data from secondary storage.
What is the grep command?
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.
What are the five variants of Linux?
1. Debian 2. Fedora 3. Redhat 4. Ubuntu 5. Cent
This is a collection of insightful articles from domain experts in the fields of Cloud Computing, DevOps, AWS, Data Science, Machine Learning, AI, and Natural Language Processing. The range of topics caters to upski... Read Full Bio