Most Frequently asked UNIX Interview Questions and Answers:
The tutorial is about the most commonly asked UNIX interview questions and answers. The main objective of the document is to measure the theoretical and practical knowledge of the UNIX operating system.
UNIX, a computer operating system, was developed at AT&T Bell Labs, Murray Hills, New Jersey in 1969. Unix is a portable operating system that can run on different hardware systems and serves as a stable, multi-user, multitasking set of programs that links the computer with users.
It was written in C and designed to facilitate multi-tasking and multi-user functionalities in an efficient way. Here, the main focus is on the theoretical part and the most commonly used syntax with UNIX.
Best UNIX Interview Questions And Answers
Q #1) What is the description of Kernel?
Answer: Kernel is the master program that controls the resources of the computer. The resource allocation to different users and tasks is handled by this section. The kernel does not communicate directly with the user and instead, it starts separate interactive program call shell to each user when logged in to the system.
Q #2) What is a single-user system?
Answer: A single-user system is a personal computer with an operating system, designed to operate by a single user at a given time. These systems become more popular since low-cost hardware and availability of a wide range of software to perform different tasks.
Q #3) What are the main features of UNIX?
Answer: Main features of UNIX are as follows:
- Machine independent
- Multi-user operations
- Unix Shells
- Hierarchical file system
- Pipes and filters
- Background processors
- Development tools.
Q #4) What is called Shell?
Answer: The interface between the user and the system is called the shell. Shell accepts commands and set them to execute for user operations.
Q #5) What are the responsibilities of a shell?
Answer: Responsibilities of a shell can be enlisted as:
- Program execution
- Input/output redirection
- Filename and variable substitution
- Pipeline hookup
- Environment control
- Integrated programming language
Q #6) What is the general format of UNIX command syntax?
Answer: In general consideration, UNIX shell commands follow the below pattern:
Command (-argument) (-argument) (-argument) (filename)
Q #7) Describe the usage and functionality of the command “rm –r *” in UNIX?
Answer: The command “rm –r *” is a single line command to erase all files in a directory with its subdirectories.
- “rm” – command for deleting files.
- “-r” – command to delete directories and subdirectories with files within.
- “*” – indicates all entries.
Q #8) Describe the term directory in UNIX?
Answer: A specialized form of a file that maintains the list of all files included in it, is called a directory. Each file is assigned to a directory.
Q #9) Specify the difference between absolute path and related path?
Answer: Absolute path refers to the exact path as defined from the root directory. Related path refers to the path related to the current location.
Q #10) What is the UNIX command to list files/folders in alphabetical order?
Answer: The ‘ls –l’ command is used to list down files and folders in alphabetical order. When you use ‘ls –lt’ command, it lists down files /folders sorted with modified time.
Q #11) Describe links and symbolic links in UNIX?
Answer: The second name for a file is called as Link. It is used to assign more than one name for a file. It is not valid to assign more than one name to a directory or to link filenames on different computers.
General command: ‘– ln filename1 filename2’
Symbolic links are defined as files that contain only the name of other files included in it. Directed to the files pointed by it is the operation of the symbolic link.
General command: ‘– ln -s filename1 filename2’
Q #12) What is the FIFO?
Answer: FIFO (First In First Out) is also called as named pipes and it is a special file for date transient. Data is read-only in the written order. This is used to inter-process communications, where data is written to one end and read from another end of the pipe.
Q #13) Describe fork() system call?
Answer: The command used to create a new process from an existing process is called fork(). The main process is called the parent process and the new process id is called the child process. The child process id is returned to the parent process and the child gets 0. The returned values are used to check the process and the code executed.
Q #14) Explain the following sentence?
It is not advisable to use root as the default login.
Answer: The root account is very important and it can lead to system damage easily with abusive usage. So, the securities that get normally applied to user accounts are not applicable to the root account.
Q #15) What is mean by Super User?
Answer: The user having access to all files and commands within the system is called a superuser. Generally, the superuser login is to root and the login is secured with the root password.
Q #16) What is the process group?
Answer: A collection of one or more processes is called a process group. There is a unique process id for each process group. The function “getpgrp” returns the process group ID for the calling process.
Q #17) What are the different file types available with UNIX?
Answer: Different file types are:
- Regular files
- Directory files
- Character special files
- Block special files
- Symbolic links
Q #18) What is the behavioral difference between “cmp” and “diff” commands?
Answer: Both commands are used for file comparison.
- Cmp – Compare given two files with byte by byte and display the first mismatch.
- Diff – Display changes that need to do to make both files identical.
Q #19) What are the duties of the following commands: chmod, chown, chgrp?
- chmod – Change the permission set of the file.
- chown – Change ownership of the file.
- chgrp – Change group of the file.
Q #20) What is the command to find today’s date?
Answer: The “date” command is used to retrieve the current date.
Q #21) What is the purpose of the following command?
Answer: This command is used to display the first part of the file README.txt which just fits on one screen.
Q #22) Describe the zip/unzip command using gzip?
Answer: gzip command creates a zip file using the given filename in the same directory.
gunzip command is used to unzip the file.
Q #23) Explain the method of changing file access permission?
Answer: There are three sections to be considered while creating/changing file access permission.
- File owner’s user ID
- File owner’s group ID
- File access mode to define
These three parts are arranged as follows:
(User permission) – (Group permission) – (other permission)
Three types of permission are
- r – Reading permission
- w – Writing permission
- x – Execution permission
Q #24) How to display the last line of a file?
Answer: This can be performed using either “tail” or “sed” commands. The easiest way is to use the “tail” command.
In the above example code, the last line of the README.txt is displayed.
Q #25) What are the various IDs in UNIX processes?
Answer: Process ID is a unique integer that UNIX uses to identify each process. The process executes to initiate other processes is called parent process and its ID is defined as PPID (Parent Process ID).
getppid() – Is a command to retrieve PPID
Every process is associated with a specific user and is called the owner of the process. The owner has all the privileges over the process. The owner is also the user who executes the process.
Identification for a user is the User ID. The process is also associated with Effective User ID which determines the access privileges for accessing resources like files.
- getpid() – Retrieve process id
- getuid() – Retrieve user-id
- geteuid() – Retrieve effective user-id
Q #26) How to Kill a process in UNIX?
Answer: The kill command accepts process ID (PID) as a parameter. This is applicable only for the processes owned by the command executor.
Syntax – kill PID
Q #27) Explain the advantage of executing processes in the background?
Answer: The general advantage of executing processes in the background is to get the possibility to execute some other process without waiting for the previous process to get completed. The symbol “&” at the end of the process tells the shell to execute a given command in the background.
Q #28) What is the command to find maximum memory taking process on the server?
Answer: Top command displays the CPU usage, process id, and other details.
Q #29) What is the command to find hidden files in the current directory?
Answer: ‘ls –lrta’ command is used to display hidden files in the current directory.
Q #30) What is the command to find the currently running process in Unix Server?
Answer: “ps –ef” command is used to find the currently running process. Also “grep” with a pipe can use to find a specific process.
Q #31) What is the command to find remaining disk space in the UNIX server?
Answer: The command “df -kl” is used to get a detailed description of disk space usage.
Q #32) What is the UNIX command to make a new directory?
Answer: “mkdir directory_name” command is used to create a new directory.
Q #33) What is the UNIX command to confirm a remote host is alive or not?
Answer: Either “ping” or “telnet” command can be used to confirm a remote host is alive or not.
Q #34) What is the method to see command line history?
Answer: The “history” command displays all the commands used previously within the session.
Q #35) Discuss the difference between swapping and paging?
Swapping: The complete process is moved to the main memory for execution. To provide the memory requirement, the process size must be less than the available main memory capacity. The implementation is easy but is an overhead to the system. Memory handling is not more flexible with swapping systems.
Paging: Only the required memory pages are moved to the main memory for execution. The size of the process does not matter for execution and it does not need to be less than available memory size. Allow a number of processes to load to the main memory simultaneously.
Q #36) What is the command to find if the system is 32 bit or 64 bit?
Answer: “arch” or “uname -a” can be used for this process.
Command with Output:
Q #37) Explain ‘nohup’ in UNIX?
Answer: “nohup” is a special command that is available to run a process in the background. The process starts with ‘nohup’ command and does not terminate even the user started to log off from the system.
Q #38) What is the UNIX command to find how many days the server is up?
Answer: “uptime” command returns the number of dates that the server is up.
Q #39) On which mode, the fault handler executes?
Answer: At the Kernel mode.
Q #40) What is the purpose of the “echo” command?
Answer: “echo” command is similar to the “ls” command and it displays all the files in the current directory.
Q #41) What is the explanation for protection fault?
Answer: When the process access a page, that does not have access permission is referred to as a protection fault. Also, when a process attempt to write on a page whose copy on write bit was set during the fork() system call is incurred for protection fault.
Q #42) What is the method to edit a large file without opening it in UNIX?
Answer: The “sed” command is available for this process ‘.sed’ stands for a team editor.
The above code will be replaced from the README.txt file.
Q #43) Describe the concept “Region”?
Answer: Continuous area of processes address space (text, data, and stack) is identified as a region. Regions are shareable among the processes.
Q #44) What is meant by user area (u-area, u-block)?
Answer: The area is only manipulated by the kernel and it contains the private data. This is unique to the process and each process is allocated to u-area.
Q #45) What is called piping?
Answer: “piping” is used to combine two or more commands together. The output of the first command work as the input of the second command, and so on. Pipe character ( | ) is represented as piping.
Q #46) What is the process to count the number of characters and lines in a file?
Answer: “wc – c filename” command is used to retrieve the number of characters in a file and the “wc –l filename” command is used to retrieve the number of lines in a file.
The above command returns the number of characters in the README.txt file.
The above command returns the number of characters in the README.txt file.
UPDATE: Added more commonly asked Unix questions.
Q #47) What do you understand by UNIX shell?
Answer: UNIX shell serves as an environment to run commands, programs, and shell scripts and also acts as an interface between the user and the Unix operating system. Shell issues “$” as the command prompt, which reads input and determines the command to execute.
For Example, $date
This command will display the current date and time.
Some of the most famous shells available with Unix variants are Bourne Shell, Korn shell, C Shell.
Q #48) Explain the term filter.
Answer: A filter is described as a program, which takes input from the standard input, and displays results to the standard output by performing some actions on it.
Standard input could be text typed on the keyboard, input from other files or output of other files serving as input. Standard output is by default the display screen.
The most popular example of Unix filter id is grep command. This program look for a certain pattern in a file or list of files and only those lines are displayed on the output screen which contains the given pattern.
Syntax: $grep pattern file(s)
Some of the options that are used along with grep command are enlisted below:
- -v: prints line that does not match the pattern.
- -n: print matched line and line number.
- -l: print file names with matching lines.
- -c: prints only count the matching lines.
- -i: matches either uppercase or lowercase.
Q #49) Write a command to erase all files in the current directory including all its subdirectories.
Answer: “rm –r*” is the command used to erase all files in the current directory including all its subdirectories.
- rm: This command is used for deleting files.
- -r: This option will erase all files in directories and sub-directories.
- ‘*’: This represents all entries.
Q #50) What do understand by Kernel?
Answer: Unix operating system is basically divided into three parts, namely, the kernel, the shell, and the commands and utilities. Kernel serves as the heart of the Unix operating system which does not deal directly with the user but rather acts as a separate interactive program for users logged in.
It performs the following functions:
- Interacts with the hardware
- Perform tasks like memory management, file management, and task scheduling.
- Control computer resources
- Helps to allot resources to different tasks and users.
Q #51) Describe key features of the Bourne shell.
Answer: Bourne shell is referred to as the standard shell. The default prompt here is ‘$’ character.
The key features of the Bourne shell include:
- Input/ Output redirection.
- Use of Metacharacters for file name abbreviations.
- Using shell variables for the customizing environment.
- Creation of programs using built-in the command set.
Q #52) Enlist the key features of Korn Shell.
Answer: The Korn shell is the most advanced as well as an extension to the Bourne Shell which is backward- compatible.
Some of the features of the Korn shell are listed below:
- Perform command line editing.
- Maintains command history so that the user can check the last command executed if required.
- Additional flow control structures.
- Debugging primitives who help programmers debug their shellcode.
- Support for arrays and arithmetic expressions.
- Ability to use aliases which are defined as the shorthand names for command.
Q #53) What do you understand by shell variables?
Answer: A variable is defined as a character string to which a value is assigned, where values could be the number, text, filename, etc. The shell maintains the set of internal variables as well as enables deletion, assignment, and the creation of variables.
Thus the shell variables are a combination of identifiers and assigned values that exist within the shell. These variables are local to the shell in which they are defined as well as work in a particular way. They may have default value or values can be assigned manually by using appropriate assignment command.
- To define a shell variable, the ‘set’ command is used.
- To delete a shell variable, ‘unset’ command is used.
Q #54) Describe the responsibilities of Shell in brief.
Answer: Apart from analyzing the input line as well as initiating the execution of the program entered by the user, Shell also serves various responsibilities.
Enlisted is a brief description of the responsibilities:
- The shell is responsible for the execution of all the programs by analyzing the line and determining the steps to be performed and then initiate the execution of the selected program.
- The shell allows you to assign values to the variables when specified on the command line. It also performs Filename substitution.
- To take care of input and output redirection.
- Performs pipeline hook-up by connecting the standard output from the command preceding the ‘|’ to the standard input of the one following ‘|’.
- It provides certain commands to customize and control the environment.
- Has its own built-in integrated programming language which is typically easier to debug and modify.
Q #55) Explain the file system in UNIX.
Answer: A Filesystem in Unix is referred to as a functional unit or a logical collection of files, where the disk is set aside to store files and inode entries.
This file system consists of the files that are organized into a multi-level hierarchy called a directory tree.
In other words, the file system is a collection of files and directories and has few features like:
- The very top of the file system is defined as the single directory called ‘root’ that contains other files and directories and is represented by a slash (/).
- These are self-independent and have no dependencies on other file systems.
- Every file and directory is uniquely identified by:
- The directory in which it resides
- A unique identifier
- All files are organized into a multi-level directory known as the ‘Directory tree’.
Q #56) What do you understand by command substitution?
Answer: Command substitution is the method that is performed every time the commands that are enclosed in backquotes are processed by the shell. This process replaces the standard output and displays it on the command line.
Command substitution can perform the following tasks:
- Invoke subshell
- Result in word splitting
- Remove trailing new lines
- By using ‘redirection’ and ‘cat’ command, allows setting a variable to the content of the file.
- Allows setting a variable to the output of the loop
Q #57) Define inode.
Answer: Whenever a file is created inside a directory, it accesses the two attributes, namely, file name and inode number.
The file name is first mapped with inode number stored in the table and then this inode number serves as a medium to access inode. Thus inode can be defined as an entry created and set aside on a section of the disk for a file system. Inode serves as a data structure and stores almost every information that is required to be known about a file.
This information includes:
- File location on the disk
- Size of the file
- Device Id and Group Id
- File mode information
- File protection flags
- Access privileges for owner, group.
- Timestamps for file creation, modifications, etc.
Q #58) Enlist common shells with their indicators.
Answer: Enlisted below are the common shells with their indicators:
|Bourne Again shell||Bash|
|Enhanced C shell||tcsh|
Q #59) Enlist some commonly used network commands.
Answer: Some commonly used networking commands in Unix are enlisted below:
- telnet: it is used for remote login as well as for communication with another hostname.
- ping: it is defined as an echo request for checking network connectivity.
- su: derived as a user switching command.
- hostname: determines the IP address and domain name.
- nslookup: performs DNS query.
- xtraceroute: method to determine the number of hoops and response time required to reach the network host.
- netstat: it provides a lot of information like ongoing network connection on the local system and ports, routing tables, interfaces statistics, etc.
Q #60) How is cmp command different from diff command?
Answer: ‘cmp’ command is basically used for byte by byte comparison of two files to determine the first mismatch byte. This command does not use the directory name and displays the first encountered mismatched byte.
Whereas, ‘diff’ command’ determines the changes that are to be performed on the files in order to make the two files identical. In this case, directory names can be used.
Q #61) What is the role of the superuser?
Answer: There are basically three types of accounts in the Unix operating system:
- Root account
- System accounts
- User accounts
‘Root account’ is basically referred to as a ‘Superuser’. This user has completely open access or say control on all files and commands on a system. This user can also be assumed as a system administrator and thus has the ability to run any command without any restriction. It is protected by the root password.
Q #62) Define piping.
Answer: When two or more commands are required to be used at the same time as well as run them consecutively, the ‘piping’ process is used. Here two commands are connected so that, the output of one program serves as the input for another program. It is denoted by the symbol ‘|’.
Enlisted below are few commands where piping is used:
- grep command: searches files for certain matching patterns.
- sort command: arranges lines of text alphabetically or numerically.
Q #63) Explain the types of pathnames that can be used in UNIX.
Answer: In a file system for any operating system, there exists the hierarchy of directories, there ‘Path’ is defined as the unique location to a file/ directory to access it.
There are basically two types of a path that are used in Unix. These can be defined as follows:
a) Absolute Pathname: It defines a complete path specifying the location of a file/ directory from the beginning of the actual file system i.e. from the root directory (/).
Absolute pathname addresses system configuration files that do not change location. It defines a complete path specifying the location of a file/ directory from the beginning of the actual file system i.e. from the root directory (/). Absolute pathname addresses system configuration files that do not change location.
b) Relative Pathname: It defines the path from the current working directory where the user is i.e. the present working directory (pwd). Relative pathname signifies current directory, parent directory as well as also refers to file that are either impossible or inconvenient to access. It defines the path from the current working directory where the user is i.e. the present working directory (pwd).
Relative pathname signifies current directory, parent directory as well as also refers to file that are either impossible or inconvenient to access.
Q #64) Explain Superblock in UNIX?
Answer: Each logical partitions in Unix are referred to as the File system and each file system contains, a ‘boot block’, a ‘superblock’, ‘inodes’, and ‘data blocks’. The superblock is created at the time of the creation of the file system.
It describes the following:
- State of the file system
- The total size of the partition
- Block size
- Magic number
- The inode number of the root directory
- Count of the number of files, etc
There are basically two types of superblocks:
- Default superblock: It has its existence always as a fix offset from the beginning of the system’s disk partition.
- Redundant superblock: It is referenced when the default superblock is affected by a system crash or some errors.
Q #65) Enlist some filename manipulation commands in UNIX.
Answer: Some filename manipulation commands along with their description is enlisted below in the table:
|cat filename||Displays contents of the file|
|cp source destination||Used to copy source file into the destination|
|mv old name new name||Move/rename and old name to the new name|
|rm filename||Remove/delete filename|
|Touch filename||Changing modification time|
|In [-s] old name new name||Creates soft link on old name|
|Is –F||Displays information about file type|
Q #66) Explain links and symbolic links.
Answer: Links are defined as a second name which is used to assign more than one name to a file. Although links are referred to as a pointer to another file it cannot be used to link filenames on different computers.
A Symbolic link is also known as the soft link. It is defined as a special type of file that contains links or references to another file or directory in the form of an absolute or relative path. It does not contain the data actually in the target file but the pointer to another entry in the file system. Symbolic links can also be used to create a file system.
The following command is used to create a symbolic link:
- Ln –s target link_name
- Here, the path is ‘target’
- The name of the link is represented by link_name.
Q #67) Explain the alias mechanism.
Answer: To avoid typing long commands or to improve efficiency, the alias command is used to assign another name to a command. Basically, it acts as a shortcut to the larger commands which can be typed and run instead.
For creating an alias in Unix, following command format is used:
alias name=’command you want to run’
Here, replace the ‘name’ with your shortcut command and replace ‘command you want to run’ with the larger command of which you want to create an alias of.
For Example, alias dir ‘Is –sFC’
Here, in the above example, ‘dir’ is another name for the command ‘Is-sFC’. Thus user now simply is required to remember and use the specified alias name and the command will perform the same task as to be performed by the long command.
Q #68) What do you know about wildcard interpretation?
Answer: Wildcard characters are some special kind of characters that represent one or more other characters. Wildcard interpretation comes into the picture when a command-line contains these characters. In this case, when the pattern matches the input command, these characters are replaced by a sorted list of files.
Asterisk(*) and Question mark(?) are usually used as wildcard characters to set up a list of files while processing.
Q #69) What do you understand by terms ‘system calls’ and ‘library functions’ with respect to UNIX command?
System calls: As the name implies, system calls are defined as an interface that is basically used in the kernel itself. Although, they may not be fully portable but these calls request the operating system to perform tasks on behalf of user programs.
The system calls appear as a normal C function. Whenever a system call is invoked within the operating system, the application program performs context switch from user space to kernel space.
Library functions: The set of common functions that are not part of the kernel but is used by the application programs are known as ‘Library functions’. As compared to system calls, library functions are portable and can perform certain tasks only in ‘kernel mode’. Also, it takes lesser time for execution as compared to the execution of system calls.
Q #70) Explain pid.
Answer: A pid is used to denote a unique process id. It basically identifies all the processes that run on the Unix system. It does not matter whether the processes are running in the frontend or in the backend.
Q #71) What are the possible return values of kill() system call?
Answer: Kill() system call is used to send signals to any processes.
This method returns the following return values:
- Returns 0: It implies that the process exists with the given pid and the system allows sending signals to it.
- Return -1 and errno==ESRCH: It implies that there is no existence of the process with specified pid. There may also exist some security reasons which is denying the existence of the pid.
- Return -1 and errno==EPERM: It implies that there is no permit available for the process to be killed. The error also detects whether the process is present or not.
- EINVAl: it implies an invalid signal.
Q #72) Enlist the various commands that are used to know about the user information in UNIX.
Answer: The various commands that are used for displaying the user information in Unix are enlisted below:
- Id: displays the active user id with login and group.
- Last: displays the last login of the user in the system.
- Who: determines who is logged onto the system.
- groupadd admin: this command is used to add group ‘admin’.
- usermod –a: user to add an existing user to the group.
Q #73) What do you know about tee command and its usage?
Answer:‘tee’ command is basically used in connection with pipes and filters.
This command basically performs two tasks:
- Get data from standard input and send it to the standard output.
- Redirects a copy of the input data to the specified file.
Q #74) Explain mount and unmount command.
Mount command: As the name suggests, the mount command mounts a storage device or file system onto an existing directory and thus making it accessible to users.
Unmount command: This command unmounts the mounted file system by safely detaching it. It also the task of this command to inform the system to complete any pending read and write operations.
Q #75) What is the “chmod” command?
Answer: Chmod command is used to change file or directory access permission and is the most frequently used command in Unix. According to mode, the chmod command changes the permission of each given file.
The syntax of the chmod command is:
Chmod [options] mode filename.
Here in the above format, options could be:
- -R: recursively change the permission of the file or directory.
- -v: verbose, i.e. output a diagnostic for every file processed.
- -c: report only when the change is made.
Q #76) Differentiate Swapping and Paging.
Answer: The difference between Swapping and Paging can be seen in the below table:
|It is the procedure of copying the entire process from main memory onto secondary memory.||It is a memory allocation technique where the process is allocated memory wherever available.|
|For execution, the whole process is moved from swap device to the main memory.||For execution, only the required memory pages are moved from swap device to the main memory.|
|The than main memory.process size must be equal to or less||The process size does not matter in this case.|
|It cannot handle the memory flexibly.||It can handle the memory more flexibly.|
The article depends on most much of the time asked UNIX order, administrator essential inquiries with itemized answers. Detailed answers likewise accessible for each question and it will help on the off chance that someone needs to improve his/her insight into UNIX. The majority of the orders accompany the normal yield.
Although, this article will help you get an idea of the preparation to be done but remember nothing is more powerful than the practical knowledge. By practical knowledge, I mean if you have never worked on UNIX, then start using it. It will be easier to answer the questions very well then.