Unix Interview Questions and Answers

Unix Interview Questions and Answers

Last updated on 23rd Oct 2020, Blog, Interview Question

About author

Kamal ((Sr Network Specialist ) )

High level Domain Expert in TOP MNCs with 8+ Years of Experience. Also, Handled Around 20+ Projects and Shared his Knowledge by Writing these Blogs for us.

(5.0) | 16547 Ratings 2167

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.

1. What is the description of Kernel?

Ans:

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.

2. What is a single-user system?

Ans:

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.

3. What are the main features of UNIX?

Ans:

Main features of UNIX are as follows:

  • Machine independent
  • Portability
  • Multi-user operations
  • Unix Shells
  • Hierarchical file system
  • Pipes and filters
  • Background processors
  • Utilities
  • Development tools.

4. What is called Shell?

Ans:

The interface between the user and the system is called the shell. Shell accepts commands and set them to execute for user operations.

5. What are the responsibilities of a shell?

Ans:

Responsibilities of a shell can be enlisted as:

  • Program execution
  • Input/output redirection
  • Filename and variable substitution
  • Pipeline hookup
  • Environment control
  • Integrated programming language

6. What is the general format of UNIX command syntax?

Ans:

In general consideration, UNIX shell commands follow the below pattern.

7. Describe the usage and functionality of the command “rm –r *” in UNIX?

Ans:

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.

8. Describe the term directory in UNIX?

Ans:

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.

9. Specify the difference between absolute path and related path?

Ans:

Absolute path refers to the exact path as defined from the root directory. Related path refers to the path related to the current location.

10. What is the UNIX command to list files/folders in alphabetical order?

Ans:

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.

11. Describe links and symbolic links in UNIX?

Ans:

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.

12. What is the FIFO?

Ans:

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.

Subscribe For Free Demo

Error: Contact form not found.

13. Describe fork(. system call?

Ans:

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.

14. Explain the following sentence?

Ans:

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.

15. What is mean by Super User?

Ans:

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.

16. What is the process group?

Ans:

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.

17. What are the different file types available with UNIX?

Ans:

Different file types are:

  • Regular files
  • Directory files
  • Character special files
  • Block special files
  • FIFO
  • Symbolic links
  • Socket

18. What is the behavioral difference between “cmp” and “diff” commands?

Ans:

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.

19. What are the duties of the following commands: chmod, chown, chgrp?

Ans:

  • chmod – Change the permission set of the file.
  • chown – Change ownership of the file.
  • chgrp – Change group of the file.

20. What is the command to find today’s date?

Ans:

The “date” command is used to retrieve the current date.

Date -command

21. What is the purpose of the following command?

README

Ans:

This command is used to display the first part of the file README.txt which just fits on one screen.

22. Describe the zip/unzip command using gzip?

Ans:

gzip command creates a zip file using the given filename in the same directory.

gzip- command

gunzip command is used to unzip the file.

gunzip -command

23. Explain the method of changing file access permission?

Ans:

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

24. How to display the last line of a file?

Ans:

This can be performed using either “tail” or “sed” commands. The easiest way is to use the “tail” command.

tail- command

In the above example code, the last line of the README.txt is displayed.

25. What are the various IDs in UNIX processes?

Ans:

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

26. How to Kill a process in UNIX?

Ans:

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

27. Explain the advantage of executing processes in the background?

Ans:

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.

28. What is the command to find maximum memory taking process on the server?

Ans:

Top command displays the CPU usage, process id, and other details.

Command:

Command

Output:

Output

29. What is the command to find hidden files in the current directory?

Ans:

  • ‘ls –lrta’ command is used to display hidden files in the current directory.

Command: 

lrta -command

Output: 

lrta- Output

30. What is the command to find the currently running process in Unix Server?

Ans:

  • “ps –ef” command is used to find the currently running process.

Also “grep” with a pipe can use to find a specific process.

Command: 

ps –ef -command

Output: 

ps –ef -Output

31. What is the command to find remaining disk space in the UNIX server?

Ans:

  • The command “df -kl” is used to get a detailed description of disk space usage.

Command:

df -kl -command

Output:

df -kl -Output

32. What is the UNIX command to make a new directory?

Ans:

  • “mkdir directory_name” command is used to create a new directory.

Command: 

mkdir -directory-name

33. What is the UNIX command to confirm a remote host is alive or not?

Ans:

  • Either “ping” or “telnet” command can be used to confirm a remote host is alive or not.

34. What is the method to see command line history?

Ans:

The “history” command displays all the commands used previously within the session.

Command:

history- command

Output:

history -Output

35. Discuss the difference between swapping and paging?

Ans:

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.

36. What is the command to find if the system is 32 bit or 64 bit?

Ans:

  • “arch” or “uname -a” can be used for this process.

Command with Output:

Command- and -outcome

37. Explain ‘nohup’ in UNIX?

Ans:

  • “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.

38. What is the UNIX command to find how many days the server is up?

Ans:

  • “uptime” command returns the number of dates that the server is up.
uptime

39. On which mode, the fault handler executes?

Ans:

  At the Kernel mode.

40. What is the purpose of the “echo” command?

Ans:

“echo” command is similar to the “ls” command and it displays all the files in the current directory.

41. What is the explanation for protection fault?

Ans:

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.

Course Curriculum

Best Unix Training with UPDATED Syllabus By Industry Experts

  • Instructor-led Sessions
  • Real-life Case Studies
  • Assignments
Explore Curriculum

42. What is the method to edit a large file without opening it in UNIX?

Ans:

  • The “sed” command is available for this process ‘.sed’ stands for a team editor.

Example,

sed

The above code will be replaced from the README.txt file.

aaa- of- README

43. Describe the concept “Region”?

Ans:

Continuous area of processes address space (text, data, and stack. is identified as a region. Regions are shareable among the processes.

44. What is meant by user area (u-area, u-block.?

Ans:

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.

45. What is called piping?

Ans:

“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.

46. What is the process to count the number of characters and lines in a file?

Ans:

“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.

wc – c -filename

The above command returns the number of characters in the README.txt file.

number -of -characters

The above command returns the number of characters in the README.txt file.

47. What do you understand by UNIX shell?

Ans:

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.

48. Explain the term filter?

Ans:

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.

49. Write a command to erase all files in the current directory including all its subdirectories?

Ans:

“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.

50. What do understand by Kernel?

Ans:

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.

51. Describe key features of the Bourne shell?

Ans:

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.

52. Enlist the key features of Korn Shell?

Ans:

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.

53. What do you understand by shell variables?

Ans:

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.

54. Describe the responsibilities of Shell in brief?

Ans:

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.

55. Explain the file system in UNIX?

Ans:

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:

1. 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 (/..

2. These are self-independent and have no dependencies on other file systems.

3. Every file and directory is uniquely identified by:

  • Name
  • The directory in which it resides
  • A unique identifier

4.All files are organized into a multi-level directory known as the ‘Directory tree’.

56.  What do you understand by command substitution?

Ans:

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

57. Define inode?

Ans:

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.

58. Enlist common shells with their indicators?

Ans:

Enlisted below are the common shells with their indicators:

ShellIndicators
Bourne Shellsh
C Shellcsh
Bourne Again shellBash
Enhanced C shelltcsh
Z Shellzsh
Korn Shellksh

59. Enlist some commonly used network commands?

Ans:

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.
Unix Shell Scripting Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

60. How is cmp command different from diff command?

Ans:

‘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.

61. What is the role of the superuser?

Ans:

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.

62. Define piping?

Ans:

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.

63. Explain the types of pathnames that can be used in UNIX?

Ans:

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.

64. Explain Superblock in UNIX?

Ans:

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.

65. Enlist some filename manipulation commands in UNIX?

Ans:

Some filename manipulation commands along with their description is enlisted below in the table:

CommandDescription
cat filenameDisplays contents of the file
cp source destinationUsed to copy source file into the destination
mv old name new nameMove/rename and old name to the new name
rm filenameRemove/delete filename
Touch filenameChanging modification time
In [-s] old name new nameCreates soft link on old name
Is –FDisplays information about file type

66. Explain links and symbolic links?

Ans:

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.

67. Explain the alias mechanism.

Ans:

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.

68. What do you know about wildcard interpretation?

Ans:

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.

69. What do you understand by terms ‘system calls’ and ‘library functions’ with respect to UNIX command?

Ans:

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.

70. Explain pid?

Ans:

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.

71. What are the possible return values of kill(. system call?

Ans:

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.

72. Enlist the various commands that are used to know about the user information in UNIX?

Ans:

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.

73. What do you know about tee command and its usage?

Ans:

‘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.

74. Explain mount and unmount command?

Ans:

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.

75. What is the “chmod” command?

Ans:

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.

76. Differentiate Swapping and Paging?

Ans:

The difference between Swapping and Paging can be seen in the below table:

SwappingPaging
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 lessThe process size does not matter in this case.
It cannot handle the memory flexibly.It can handle the memory more flexibly

Are you looking training with Right Jobs?

Contact Us

Popular Courses