UNIX Interview Questions and Answers for 2024

The Linux system is one of the most potent and fastest computer operating systems. Nearly 90% of the fastest computers worldwide have Linux OS installed. If you want to be hired as a Linux expert in a company, here are a few things that you must know, and the interviewer can ask you. There are a wide variety of jobs available for people who are skilled in UNIX, as UNIX and its variants (such as Linux) are widely used in many different industries. The specific job responsibilities and requirements will vary depending on the organization and industry in which you work. We have listed the most frequently asked Linux interview questions and answers so that you can ace your next Linux interview.

  • 4.7 Rating
  • 65 Question(s)
  • 30 Mins of Read
  • 5958 Reader(s)

Beginner

UNIX is a widely-used and influential operating system that has shaped many of the computing technologies that are in use today, so learning about UNIX can provide a valuable foundation for understanding how computers and networks operate.  

UNIX is also known for its strong emphasis on security and stability, which makes it a popular choice for use in servers and other critical systems. Additionally, many of the concepts and tools that were developed for UNIX have been widely adopted in other operating systems, so learning about UNIX through KnowledgeHut online programming certification can be useful even if you do not plan to use it directly.

The full form of UNIX is "UNiplexed Information and Computing Service". The name UNIX was originally intended to be a pun on the name "Multics", which was a project that was being developed at the same time as UNIX and was intended to be a more comprehensive operating system.

The "UNI" part of the name was intended to stand for "UNiplexed", to contrast with the "MULTI" in "Multics". "UNiplexed" refers to the fact that UNIX was designed to be used on a single computer, rather than a network of computers like Multics. The "X" in "UNIX" was originally a placeholder that was intended to indicate that the name was still under development, but it eventually becampart of the official name of the operating system.", to contrast with the "MULTI" in "Multics". "UNiplexed" refers to the fact that Unix was designed to be used on a single computer, rather than a network of computers like Multics. The "X" in "Unix" was originally a placeholder that was intended to indicate that the name was still under development, but it eventually became part of the official name of the operating system.

UNIX is an operating system that was developed in the late 1960s, and it is written in the C programming language. However, UNIX is also designed to support other programming languages, such as Python, Perl, and Bourne Shell Scripting. Additionally, UNIX includes a set of tools and utilities that are written in various programming languages, so the "language of UNIX" is not just one specific programming language. Instead, UNIX is a platform that can support a wide range of programming languages.

Yes, Apple's operating system, macOS, is based on the UNIX operating system. Apple has incorporated many of the features and technologies that are found in UNIX into macOS, and as a result, macOS is sometimes referred to" as a "UNIX-like" operating system. Yes, Apple's operating system, macOS, is based on the Unix operating system. Apple has incorporated many of the features and technologies that are found in Unix into macOS, and as a result, macOS is sometimes referred to as a "Unix-like" operating system.  

In addition to using UNIX as the foundation for macOS, Apple has also made significant contributions to the development of the UNIX operating system. For example, Apple has contributed code and technology to the open-source version of UNIX known as FreeBSD.

UNIX was developed in the late 1960s at AT&T's Bell Labs by a team of programmers led by Ken Thompson and Dennis Ritchie. Thompson and Ritchie were working on an operating system called Multics (Multiplexed Information and Computing Service), but they decided to create a new operating system that was simpler and more efficient. Unix was developed in the late 1960s at AT&T's Bell Labs by a team of programmers led by Ken Thompson and Dennis Ritchie. Thompson and Ritchie were working on an operating system called Multics (Multiplexed Information and Computing Service), but they decided to create a new operating system that was simpler and more efficient.  

They named their new operating system UNIX, and it quickly became popular due to its portability and modular design. Over the years, UNIX has evolved and has been used as the foundation for many other operating systems, including Linux, macOS, and Android.

Kernel is a master program that allows the user to control the computer resources. This section executes the resource allotment to different tasks and users. 

Kernel is a central component of an OS that manages operations of hardware and computer. It helps manage the operations of memory and CPU time and is one of the most important components of an operating system.  

Kernal act as a bridge between application and data processing performed at hardware level using inter-process communication. Kernel loads first in the memory ( when the operating system is loading) and stays in the memory till the operating system restarts. It is responsible for different tasks such as task management, memory management and disk management.  

Kernel has a process table that contains a per process region table and also helps in loading an executable file in the memory. Some of the common objectives of Kernel are:  

  • To decide the state of incoming processes 
  • To establish the communication between the user level application and hardware 
  • To control disk management 
  • To control memory management  
  • To control task management

Expect to come across popular Shell scripting interview questions like this.

UNIX has a graphical user interface just like the Windows operating system, which makes it easy the navigation and a good supportive environment. The internal design view of this OS is called architecture. A general UNIX architecture comprises mainly four different layers: Kernel, Shell (system call interface) and User application libraries/tools, utilities.   

A Kernel is called the core layer of an operating system that interacts with the system hardware. It provides API through the system calls to process the user's request. Kernel helps in signal handling, inter process communication, network services, file system services, synchronization, hardware monitoring and more. The kernel helps control the hardware of the computer and stays in the core of architecture. The system works as an interface between the kernel and other libraries. These libraries contain general functions and are at the top of the system calls.  

Kernel: Kernel acts as a central core of the operating system that interacts with the hardware. The main functions of the Kernal are:  

  • Computer hardware like discs, printers and memory are controlled by Kernel. 
  • The Kernel controls, schedules and executes various user-defined tasks. 
  • It manages the data storage and controls the computer access by various users. 
  • It is composed of different sub-components like header-files, device drivers to control hardware and different configurations like boot code.  

Shell: A shell is the interface between the kernel and the user. Users interact with the shell using different shell commands. A shell has two prime responsibilities like interpreting the commands given by the users and executing them using the Kernels, providing the programming ability to the users to write the shell commands for a shell script to do different tasks.  

Commands: Some of the most important categories of commands used by the UNIX operating system are - ''sh'' - shell commands that provide a primary user interface. 'Utilities' forming the core toolkit of UNIX commands come with sub-categories like system utility supporting administrative tools and User utilities for environment management tools.  

There are also few commands ( also mentioned in the UNIX Commands Interview questions)  for general purpose applications like typesetting and document-formatting. There are some packages like Tex and Ghostscript, and provide support for the inter-system communications as well as inter-user communications.  , and provide support for the inter-system communications as well as inter-user communications.

UNIX basic interview questions like this are a must-know for anyone heading into the technical round.  

Single user operating system, also called a single-tasking operating system helps accessing the computer at the specific time. It allows permission to access the personal computer through the single user, but does support multiple profiles.  

Single-user can also be used for doing official work and other environments, which means this supporting system doesn't need any memory protection, file protection and security system. The computer-based on this OS has a single processor that helps in executing the single program. Some of the features single-user operating system are:  

  • File management  
  • Memory management  
  • Input/output management 
  • Interpreting user's commands 
  • Resource allocation  
  • Managing process 

Types of Single-user Operating Systems:  

  • Single user single- Tasking 
  • Single User Multi-Tasking 

Single-User Single-Tasking: Single user operating systems allow a single user to execute the one program at one specific time. This OS is designed for wireless phones and two-way messaging.  

Single User Multi-Tasking: This operating system allows single users to run multiple programs at the same time; single users can perform multiple tasks at the same time. This type of operating system is found in laptops and personal desktops. This single user multi-tasking can be cooperative and pre-emptive.  

  • Co-operative: This happens by relying on every process to give time to other methods in a specific manner. Some advantages of the Cooperative user system are that they are cost effective and less memory is used.  
  • Pre-emptive: This operating system compares the central processing time by allocating the single slot to every program. 

System Libraries are specialized programs or functions that allow system utilities or application programs to access the capabilities of Kernel. These libraries implement the functionalities of the operating systems and don't require permissions from kernel module code access. Libraries can be linked with another libraries and other object files to create executables. Libraries are of two types:  

Static Libraries: To build a static library, you must compile all source files into .o files and then use the command ar to archive a library of .o files. You can also use man ar to check all the options, one set is described below:  

option purpose  

  • c- create a new library  
  • q- add the named file to the end of the archive  
  • r- replace the named library member  
  • t- print the table of archive contents 

For instance- ar cq libfoo.a *.o will create a new library ''libfoo.a from the .o files. You may also see the ar command in the makefile, which means you will use the makefile variable rather than the *.o.  

Dynamic Libraries: Dynamic libraries work when the program runs not when the program is compiled. This helps decrease the size of the stored executables and allows new versions of the libraries to get linked to the run time. Creating a shared library is a two step process- first the source files should be compiled as sharable objects and for this you can use the -fPIC flag to g++, i.e. g++ -fPIC -o foo foo.cc 

this will compile the foo.cc in the sharable foo.o.  

To combine multiple sharable .o files into the shared library, you can use the following command:  

Id -G*.o -o libfoo.so 

This combines all the .o files into the one shared library called libfoo.so. The -o option specifies the output file, the -G option is to build the shared library.

It's no surprise that this question pops up in UNIX interviews once in a while.

UNIX Utilities is a well-defined set of commands used by portable shell scripts. It is also referred to as a command that performs operating-system-related tasks. Generally, system utilities are responsible for maintenance of computers and are used for supporting and enhancing the programs in the computer. Some of the most common examples of utilities are:  

  • Anti-virus: to scan the computer for viruses 
  • Data Compression: to compress the files 
  • Cryptographic: to encrypt and decrypt files 
  • Disc Compression: to compress content of disc for increasing the disc capacity  
  • Disc Cleaner: to find files that are hidden and are not in use for the longest time

To find a file under the UNIX operating system, you need to use the ''find'' command. The Find command will search files and directories under the operating systems. You can also specify criteria for searching the files. If there are no criteria set, all the files will return to the current working directory.  

Another way you can find the file is by using ''locate'' command. The locate command will find files by name; it will read the database prepared by the updatedb and will display the file name that is at least similar to the one pattern of the screen.  

Here's the syntax to be followed:  

  • find /dir/to/search -name "file-to-search" 
  • find /dir/to/search -name "file-to-search" - print 
  • find /dir/to/search -name "file-to-search" - ls 
  • find /dir/to/search -name "regex" - print  

A shell in UNIX is a collection of computer operating systems that let different users perform multiple tasks. A shell is a medium provider that helps interact with the kernel, which is a CLI ( Command Line Interface) to the UNIX system. The shell works by collecting the input from the users and executing the program based on their inputs and displaying the output after execution. A shell is of two types:  

Bourne shell: If you are using this type of shell, the $ character is the default prompt. The Bourne shell is divided into following subcategories:  

  • Korn shell (Ksh) 
  • Bourne shell (sh) 
  • Bourne Again shell (bash) 
  • POSIX Shell (sh) 

C-type shell: If you are using the C-type shell, the % character becomes the default prompt. Different types of C-type shells are:  

  • C Shell (csh) 
  • TENEX/TOPS C shell (tcsh) 

Bourne shell is installed as /bin/sh on most versions of UNIX and this is why this shell is used for writing scripts that can be used on various versions of UNIX.  

We need a UNIX shell because:  

  • It comes with a set of in-built commands or programs that are needed for the shell scripting.  
  • Shell scripting saves a lot of time and allows you to write a single command instead of writing multiple commands.  

Shell analyzes every line you type and makes the execution of the respective program, but it also has other responsibilities like:  

Program execution

The shell is responsible for executing all programs that you request from your terminal. Every time you type in a line in the shell,  it analyzes the line and identifies the other steps. Every line in the shell follows the same basic syntax:  

program-name arguments 

The line that is typed with the shell is called the command line; the shell scans this line to identify which argument to pass to the program. The shell uses special characters to identify where the program starts and ends; these special characters are called Whitespace characters.  

Variable and Filename Substitution

Just like any other programming language, you can assign values to the variable. Whenever you assign these variables to the command line, the shell substitutes the assigned value. The shell is also responsible for performing the filename substitution on the command line. It scans the command line to identify the filename substitution characters *, ?, or [...] before defining the file name.  

I/O Redirection

Shell takes care of the input and output redirections on the command line and scans the command line to identify the occurrence of special characters like <, > or >>.  

Pipeline Hookup

Just like the shell scans the command line to find special characters, it can also look for the pipe character |. For every such character it finds, the pipeline hookup connects the standard output from the command preceding the | with the standard one following the |. Later, it ran execution on both programs. This means, when you type: 

who | wc -1 

the shell automatically finds the pipe symbol that separates the who and wc. It connects the standard output to the input and executes both commands.  

Environmental control  

Shell also has certain commands that let you customize your environment. The environment includes a list of directories to be searched, home directory and the characters that shell displays to let you type in the command.  

Interpreted Programming Language  

The shell comes with its own built-in interpreted programming language. This means that the shell analyzes every statement in the language and then executes it. Unlike C and FORTRAN, where the statements are compiled into the machine language before execution, programs developed in this are easy to debug and modify.

A frequently asked question in UNIX interviews, don't miss this one.

The command that can be used to print a file – Draft with 66 lines is 

Syntax - pr – 160 draft 

Note: The –I option states a specific length.

LD_Library_Path is widely known as an environment variable that users can utilize to debug a non-standard or a new library. In addition, users can also use it to recognize the directories that users need to search. The users can set the variable using the following command: 

Syntax - setenv—LD_LIBRARY_PATH--$PATH 

In UNIX LD_Library_Path is used to tell the dynamic link loader, which is a small program that starts your applications to identify where to look for the dynamic shared libraries. In this a colon (:) is used to separate the list of directories, which is checked even before the built-in search paths and conventional locations. Some of the most common uses of LD_Library_path are:  

  • To compare the new versions of shared libraries with already compiled applications.  
  • To relocate the shared libraries to keep the previous versions alive.  
  • To create a self-sufficient system and relocatable environment for big applications.

The users should disable "Finger Service" on the Linux Server as the remote user(s) can get crucial data using this command regarding the system. 

some other applications that you may not need on your server are:  

  • smbd and nmbd: smbd and nmbd are the daemon of Samba Process, which you can kill or disable from starting automatically.  
  • Telnet: If you don't need any bidirectional interactive text-oriented communication on the Internet, you can turn off this from starting at booting.  
  • rexec: The Remote Process Execution or rexec let you execute shell commands on the remote computer; so if you don't need it simply shut down this command.  
  • rlogin: If you don't need to log in another host you can disable this command.  
  • automount: You can shut this process down if you don't want to mount different file systems to bring the network files.  

If you want to check the presently logged-in user on UNIX, you can use the whoami command as follows: 

Syntax: %whoami 

O/P - test (test as username). It gives the users a name utilizing which has been used for logging into the system. 

Or you can use the following syntax:  

To get the current user name, type: 

echo "$USER" 

Get the current user name and store in a shell variable called $u: 

u="$USER" 
echo "User name $u" 

To check all the logged-in users onto the UNIX Platform, you can insert the command - %who. 

Also, following files keep all the login records on Linux and UNIX-like systems: 

/var/run/utmp  Keeps and allows you to identify information about who is currently using the system. There may be more Linux and UNIX users currently using the system, because not all programs use utmp logging. In other words, poorly written apps, hidden programs, malware, and other bad stuff will not be useful to list logged in users. 

/var/log/wtmp – Keeps records of all logins and logouts. 

We simply cannot read these files using cat command/grep command/egrep command as file is in binary database format. Hence, we use the following commands to find currently logged in users in Linux and UNIX-like systems. 

Linux Command To List Current Logged In Users 

  • w command – Shows information about the users currently on the machine, and their processes. 
  • who command – Display information about users who are currently logged in. 
  • users command – See the login names of the users currently on the system, in sorted order, space separated, on a single line. It reads all information from /var/run/utmp file

Using the command %pwd, we may determine where a user is located on the UNIX system. 

This command will represent your current working directory. 

For instance, check if the file you are working on is in the directory bin by simply typing the command line option -%pwd to pwd. 

First, type the command %cp to copy the file. 

Syntax: %cp file fileB (to copy the file within the same directory). 

To Copy the file in different directories, enter the following command, 

Syntax: %cp source/filename location (target location)

First, type the command %mv to move the file. 

Syntax: %mv fileA fileB (to move the file within the same directory). 

To Move the file to different directories, enter the following command, 

Syntax: %mv source/filename location (target location) 

To create a new file in UNIX and write to it, you can use the "echo" command and ">" operator. The echo command writes a specified message to the terminal, and ">" operator redirects the output of the echo command to a file. 

Here is an example of how you can use these commands to create a new file called "newfile.txt" and write the message "Hello, world!" to it: 

echo "Hello, world!"> newfile.txt 

If the file "newfile.txt" already exists, the above command will overwrite the file with the new message. If you want to append the message to the end of the file instead of overwriting it, you can use ">>" operator instead of ">" operator. For example: 

echo "Hello, world!" >> newfile.txt 

This will add the message "Hello, world!" to the end of the file "newfile.txt", without overwriting any existing content. 

Keep in mind that The "echo" command and ">" and ">>" operators are not specific to UNIX. They are also available on other operating systems, such as Linux and macOS.Keep in mind that The "echo" command and the ">" and ">>" operators are not specific to Unix. They are also available on other operating systems, such as Linux and macOS. 

There are several commands that you can use to view the content in a file, including cat, more, less, tail, and head. 

Usage – %cat filename 

It will allow you to view all the content saved in a specific file. The command – CAT- combines and opens multiple data in a file.

The users are split into three different types: 

  • User: Users who have created the file in the first place. 
  • Group: Group of users who share the same benefits, just like the original owner.  
  • Others: Members with access to the folder where you've stored the files.  

Users will have three different access rights from a file point of view. I.e., Read, Write, then Execute. 

  • Read: The user is authorized to view the file's contents. R is used to represent it. 
  • Write: The file's contents may be changed by the user. W is used to express it.  
  • Execute: The user is only allowed to run the files. It is symbolized by x.  

With the ls command, one may view these permission privileges. 

A simple way of changing a file's permission is using the SHMOD command. 

Syntax: %chmod 777 filename 

You can use the chmod command to set permissions in either of two modes: 

  • Absolute Mode – This mode uses numbers to represent file permissions. When you change permissions by using this mode, you show permissions for each triplet by an octal mode number. 
  • Symbolic Mode – This uses combinations of letters and symbols to add or remove permissions.

Intermediate

UNIX platform includes two different wildcards, as explained below: 

  • Users can use a wild asterisk card to replace n no. of characters. 
  • Users can use Question Mark wild card to replace a single character.  

A wildcard is a symbol that takes the place of an unknown character or different characters. Some of the most commonly used wildcards are the (*) asterisk and (?) question mark.  

The (*) asktrisk:  

This wildcard represent the number of unknown characters; you can use it for searching files or documents which only have partial names. Let us say, you are looking for ''cheese'', you may get following results:  

  • cheese 
  • cheesecake 
  • cheesedip.txt 

but, if you enter *cheese, you may get the following searches:  

  • Swisscheese 
  • sliced.cheese 
  • stringcheese 

(?) The Questionmark: 

 The Questionmark shows one unknown character. You can use it when you have list of files with the same names. For instance, if you enter text?.txt as your search query, you may find these files:  

  • take1.txt 
  • taken.txt 
  • take2.txt 

One of the most frequently posed UNIX Shell scripting interview questions, be ready for it.  

Users can compress a given file by entering a gzip command. 

Syntax – %gzip filename 

O/p. The file's size would have decreased significantly, and the file extension would now be text.txt.gz. 

Users can decompress a given file by entering a gunzip command. 

Syntax – %gunship filename 

O/p. The file's size would have increased significantly, and the file extension would now be text.txt. 

To check real-time logs and data in UNIX, users can utilize a tail command. This command will default showcase the last ten lines of the given file. 

Usage – %tail test.log 

If you want to monitor the latest updates in the log file, you can use the –f option to receive updates. 

Usage – %tail –f test.log

LVM (Logical Volume Manager) is a disk partitioning system that allows for the creation, management, and resizing of logical disk volumes. It works by abstracting the physical storage devices, such as hard drives or SSDs, into logical storage pools called "volume groups". These volume groups can then be divided into smaller logical units called" "logical volumes", which can be used as if they were physical partitions. 

One of the main benefits of LVM is that it allows for easy resizing of partitions. With traditional partitioning systems, resizing a partition typically requires backing up the data, deleting the partition, and then creating a new partition with the desired size. With LVM, you can resize logical volumes without having to delete them, and without having to take the system offline. 

LVM also allows for the creation of snapshots, which are read-only copies of logical volumes. This can be useful for backups, or for testing and development purposes. It let you to use multiple physical storage devices as one large storage pool. This can be used to increase the storage capacity of your system, or to create a RAID-like setup for increased data redundancy. 

Here are a few steps to shrink the LVM partition's size: 

  • Disembark the file system through the unmount command. 
  • Utilize the command – resize2fs like: resize2fs /dev/mapper/myvg-mylv 10G 
  • Then use the command – lvreduce like: lvreduce -L 10G /dev/mapper/myvg-mylv 
  • By doing so, you can shrink the LVM partition's size and settle the filesystem's size up to 10 Giga Bytes. 

The maximum length (in bytes) of a UNIX Filename is 255 bytes. This filename does not include the pathname. So, the path name of total length can quickly suppress 255 characters.

A staple in UNIX interview questions and answers, be prepared to answer this one.  

There are mainly two types of user modes in Linux, 

  • Command Line  
  • GUI 

Hard Links are defined as existing files in the Linux system. You can create limitless hard links for every file by entering the command - $ ln [original filename] [link name]. 

On the other hand, Soft Link is considered a symbolic link. In maximum cases, Soft Links act as a file that leads to another file. You can create soft links by entering the command – $ ln -s [original filename] [link name]. 

In a file system, a hard link is a directory entry that associates a name with a file on a file system. It is created using the ln command and allows multiple names to be associated with the same file. The file is not deleted until all hard links to it are removed. 

A symbolic or soft link, on the other hand, is a special type of file that contains a reference to another file or directory. It is created using the ln -s command and allows you to create a link to a file or directory located in a different part of the file system. Unlike a hard link, a symbolic link does not contain the actual data of the target file, it simply points to it. If the target file is deleted or moved, the symbolic link will be broken. 

In general, hard links are more efficient because they do not require the operating system to follow a link to find the target file. However, symbolic links offer more flexibility because they can be used to link to files and directories on other file systems or on remote servers.

This question is a regular feature in UNIX interviews, be ready to tackle it.  

On the Linux platform, there are three standard streams that are used to communicate with a program: 

  • Standard Input (stdin): This is a stream that is used to send data to a program. By default, it is connected to the keyboard, so you can type input into a program. 
  • Standard Output (stdout): This is a stream that is used to receive data from a program. By default, it is connected to the terminal, so you can see the output of a program. 
  • Standard Error (stderr): This is a stream that is used to receive error messages from a program. By default, it is also connected to the terminal, so you can see error messages that are generated by a program. 

You can redirect these streams to or from files, or you can pipe them to other programs. This allows you to manipulate the data that is being sent to or received from a program. 

The command users can enter to create a tape archive file and send it to a tape device is tar -cvf /dev/tape /home. 

The –xvf command is entered to extract a specific file from the archive. 

Telnet is a network protocol that was commonly used in the past to provide a command-line interface for remotely managing a system over a network. It allows a user to log in to a remote system and execute commands as if they were sitting at the local console. 

Although Telnet is still available on many systems, it is generally considered to be insecure because it transmits data, including passwords, in plaintext over the network. This makes it vulnerable to interception and abuse by attackers. 

For this reason, it is generally recommended to use a secure alternative such as Secure Shell (SSH) for remote access to a Linux system. SSH encrypts all data transmitted over the network, including passwords, making it much more secure than Telnet. 

Other alternatives to Telnet for remotely managing a Linux system include Remote Desktop Protocol (RDP) and Virtual Network Computing (VNC). These protocols allow you to remotely access the graphical user interface (GUI) of a system, rather than just the command-line interface. 

In the Linux system, every directory and file has three different owner categories named User, Group, and Others. For these three owners, three different permissions are required as below: 

  • Read: It allows the user to open a file, read it, and make a list of all the content in the directory.   
  • Write: It allows the users to make changes in the file's content. In addition, the user can also remove or even rename some files in the directories.   
  • Execute: The user can access and run a file in the directory through this permission.

The VI Editor is the most basic text editor tool that can be seen in the majority of Linux distributions. Here are some different types of VI Editor Modes: 

  • Regular Mode/Command Mode: The default VI editors' mode is Regular Mode/Command Mode. Typically, it is extensively utilized to view and even write commands to perform unique, or special VI asks.   
  • Edit Mode/Insertion Mode: You can utilize the Edit Mode/Insertion Mode to insert or edit some text in the file. Using this mode, you can even delete some text.   
  • Replacement Mode/Ex Mode: Replacement Mode/Ex Mode is usually utilized for command execution and file saving. You can also use this mode to overwrite a text.

Correct usage of tools can be one of the top UNIX interview questions for experienced professionals, be ready to tackle it.

Yes, rm-r* is used to erase all files from the current directories and subdirectories. You can use rm for deleting files, but with the ''-r'', you can delete all the files in the directories and subdirectories.

A relative path is a file path that specifies the location of a file relative to the current working directory. For example, if the current working directory is /home/user/documents, a relative path to a file report.txt in the /home/user/documents/project1 directory would be

project1/report.txt.

An absolute path, on the other hand, is a file path that specifies the location of a file relative to the root directory of the file system. The root directory is represented by a forward slash (/) and is the starting point for the entire file system.  

An absolute path to the same file report.txt in the /home/user/documents/project1 directory would be

/home/user/documents/project1/report.txt.

The main difference between relative and absolute paths is that an absolute path is independent of the current working directory, while a relative path is dependent on it. This means that if you change the current working directory, a relative path to a file will change, but the absolute path will remain the same.

UNIX basic interview questions test your conceptual knowledge. Expect to come across this popular question in your next interview.

In computing, a FIFO (First In, First Out) is a type of buffer or queue that stores a stream of data in which the first data that is added to the queue will be the first one to be removed. This is similar to a line at a grocery store, where the first person to get in line will be the first one to be served. 

FIFO is often used to communicate between processes, where one process writes data to the FIFO and another process reads the data. Because the data is read in the same order that it was written, the FIFO ensures that the processes are synchronized and that the data is processed in the correct order. 

In Linux and other UNIX-like operating systems, a FIFO is implemented as a special file type that has the same name as the FIFO and is created using the mkfifo command. Processes can then read from or write to the FIFO using standard file input/output functions. 

In a UNIX-like operating system, a directory is a file that contains a list of other files and directories. Directories are used to organize and group files together, and can be nested within other directories to create a hierarchical file system. 

The top-level directory in a UNIX-like system is the root directory, which is represented by a forward slash (/). All other directories and files in the system are contained within the root directory or one of its subdirectories. 

Some common directories in a UNIX-like system include: 

  • /bin: This directory contains executables (binary files) that are used by the operating system and are available to all users. 
  • /etc: This directory contains configuration files that are used to control the system. 
  • /home: This directory contains the home directories of individual users. Each user has their own subdirectory under /home where they can store their own files. 
  • /lib: This directory contains library files that are used by the operating system and other programs. 
  • /tmp: This directory is used for storing temporary files that are created by programs. 

Also, you can use the ls command to list the contents of a directory, and the cd command to change the current working directory.  

''-l'' command is used to list all the files and folders in alphabetical order.

Paging: Paging is a memory management technique that assigns the process to a non-contiguous address area. Paging is accomplished by dividing the RAM into different fixed-size sections called frames. A process's logical memory is further divided into identical fixed-size units called pages.  

Paging is simply a memory management method that lets the system store and get data from the secondary storage to be used in RAM.  

  • It allows a process's memory address space to be non-contiguous.  
  • It's more flexible as the pages of the process is only moved. 

Swapping: Swapping is the memory management technique that removes inactive programs from the main memory of the computer. Swapping typically affect the performance and helps in executing large operations concurrently.  

  • It allows various programs in the operating system to run simultaneously.  
  • It is less flexible because it moves the complete process back and forth between RAM. 
  • As compared to paging, Swapping allows few programs to run the main memory.  
  • It lets CPU access more quickly.  

This is done to free up space in memory (also known as RAM) for other programs to use. It is used on systems with limited amounts of RAM to allow them to run programs that are larger than the available memory. When a program that is stored on the hard disk is needed, the OS will swap it into memory and execute it. When the program is no longer needed, the OS will swap it back out to the hard disk to make room for other programs. 

The process of swapping can be slow, as accessing data from a hard disk or SSD is slower than accessing data from memory. This can cause a noticeable slowdown in the performance of the system, especially if a lot of swapping occurs. 

To reduce the need for swapping, you can try to close unnecessary programs or increase the amount of available RAM on the system. On systems with a lot of RAM, swapping may not be necessary at all. 

A must-know for anyone heading into a UNIX interview, this is one of the most frequently asked UNIX interview questions.  

These are file management commands. These are used for: 

  • chmod - It changes the permission set of a file 
  • chown - It changes the ownership of the file. 
  • chgrp - It changes the group of the file. 

$ chmod g+w testfile: changes permission for a user group to write. 

$ chown sroy8091 testfile: changes the owner of testfile to sroy8091. 

$ chgrp moderators testfile: changes a group of testfile to moderators. 

UNIX Shell scripting interview questions like this requires you to present a detailed answer with examples.

nohup is a special command used to run a process in the background. This even works when a user logs off from the system. You can use it to create daemon processes or clean the script of logs.

Advanced

In a UNIX-like operating system, a daemon is a background process that runs independently of the user's interaction with the system. Daemons perform a variety of functions, such as providing services to other programs, scheduling tasks, and collecting system data. 

Unlike normal programs, daemons do not have a user interface and are not usually directly interacted with by the user. They run in the background and are typically started when the system boots up and continue to run until the system shuts down. 

Some common examples of daemons include the sshd daemon, which provides secure remote access to the system, and the cron daemon, which is used to schedule tasks to run at specific times.

A filter is a program or function that processes input data and produces output data based on specific criteria. Filters are often used to modify or transform the data in some way, such as sorting it, searching for specific patterns, or converting it from one format to another. 

In the context of a UNIX-like operating system, a filter is a command-line utility that reads data from standard input, processes it in some way, and writes the output to standard output. Filters can be used in combination with other commands using pipes (|), which allow the output of one command to be passed as the input to another. 

For example, the grep command is a filter that searches for lines in its input that contain a specific pattern and writes the matching lines to standard output. You could use it to search for a specific word in a file like this: 

grep "word" file.txt 

You can also use the sort command to sort the lines of its input and the uniq command to remove duplicate lines. For example, to sort the lines of a file and remove duplicates, you could use the following command: 

sort file.txt | uniq 

There are many other filters available in a UNIX-like system, and you can also write your own custom filters using a programming language such as Python or C.

MBR (Master Boot Record) is the boot sector of a hard disk or solid-state drive (SSD) in a computer. It is a small program that is stored in a specific location on the disk and is executed when the computer starts up. 

The MBR is responsible for loading the operating system and transferring control to it. It contains a bootloader program that is responsible for loading the operating system kernel into memory and starting it. The MBR also stores a partition table that describes the layout of the disk's partitions and where they are located. 

The MBR is usually created when a hard disk or SSD is formatted, and it is stored in the first sector of the disk. It is typically 512 bytes in size and is composed of three parts: the bootstrap code, the partition table, and the boot signature. On modern systems that use the Unified Extensible Firmware Interface (UEFI) instead of the traditional BIOS, the MBR is replaced by the GUID Partition Table (GPT).

A common question in Shell scripting interviews, don't miss this one.

Following are the fundamental components of the file system: 

  • Boot lock 
  • Inode lock 
  • Data Block 
  • Super Block 

One of the most frequently posed UNIX interview questions, be ready for it.  

  • telnet: This is used for remote login and for communication with another hostname. 
  • ping: This is used for checking network connectivity. 
  • hostname: This gives the IP address and domain name. 
  • nslookup: This performs a DNS query. 
  • xtraceroute: This is used to determine the number of hops and response time required to reach the network host. 
  • netstat: This provides information about system and ports, routing tables, interface statistics, etc. 
  • tcpdump: This provides info about both incoming and outgoing network traffic.

A staple in UNIX viva questions, be prepared to answer this one.  

In the UNIX operating system, a "superblock" is a special block of data that is used to store important information about the file system. This information includes details about the size of the file system, the number of blocks it contains, the number of inodes (data structures used to store information about files and directories), and other important metadata. 

The superblock is usually stored at a fixed location on the file system and is used by the operating system to locate and access other data structures and files on the file system. The superblock is a critical part of the UNIX file system, as it contains the information needed to mount the file system and make it accessible to users. 

If the superblock is damaged or becomes corrupted, it can cause serious problems with the file system, including data loss and filesystem instability. Therefore, it is important to ensure that the superblock is protected and properly maintained. In some cases, it may be necessary to restore the superblock from a backup in order to repair a damaged file system. 

There are basically two types of superblocks: 

  • Default superblock: It is a fixed offset from the beginning of the system's disk partition. 
  • Redundant superblock: There are multiple copies of superblocks of a default one and are referenced when the default superblock is affected by a system crash or some errors. 

Some of most common manipulation commands I have read are: 

  • cat filename - Displays contents of the file. 
  • cp source destination - Copy the source file into the destination. 
  • mv old_name new_name - Move/rename. 
  • rm filename - Remove/delete filename. 
  • touch filename - creating/changing modification time. 
  • In [-s] old_name new_name - Creating a soft link on an old name. 
  • Is –F - Displays information about the file type. 
  • ls -ltr - This will display in long format sorted by modified time with oldest first. 

kill() system call sends signals to any process which further takes suitable action according to the signal. It takes two arguments, first is PID, to which you want to send a signal and the signal you want to send is second. This method returns the following return values: 

  • 0 - means that the process exists with the given PID and the system allows sending signals to it. 
  • -1 and errno==ESRCH - means that the process/process group with specified PID does not exist 
  • -1 and errno==EPERM - means that the sender has no permission to send a signal to the target process. 
  • EINVAL - means an invalid signal was specified 

In the UNIX operating system, the "mount" and "unmount" commands are used to attach and detach file systems from the file hierarchy. When you mount a file system, you are making it available for use on the system by attaching it to a directory (also known as a mount point) in the file hierarchy. Once a file system is mounted, you can access the files and directories on it as if they were part of the local file system. 

The "mount" command is used to mount file systems, and it has the following syntax: 

mount [-options] device mount_point 

The "device" argument specifies the device that contains the file system to be mounted, and  the "mount_point" argument specifies the directory where the file system will be attached. 

The "unmount" command is used to detach a file system from the file hierarchy, and it has the following syntax: 

unmount mount_point 

The "mount_point" argument specifies the directory where the file system is currently attached. 

Both the "mount" and "unmount" commands require superuser privileges to execute.

Prepare for this and other UNIX commands for interviews, as these can be follow-up questions very easily.

Zombie processes are those child processes that get finished before the parent process. So after finishing up, the process structure and address space are removed and freed back to the system but the entry in the process table still exists. To be able to get the status of the child process the parent calls wait(). In the interval between the child terminating and the parent calling wait(), the child is said to be a ''zombie''.

The "date" command is used to retrieve the current date. 

  • bash-4.3$ date 
  • Sat Dec 31 19:18:57 IST 2022 
  • bash-4.3$ 

Date command 

sh-4.3$ more README.txt 

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

A region is a continuous area of processes address space (text, data, and stack). Regions are shareable amongst the processes.

In the UNIX operating system, the term "u-area" (also known as the user area or "user structure") refers to a data structure that is used to store information about a particular user or process.  

The u-area typically contains information such as the user's ID, group ID, and other identifying information, as well as pointers to other data structures and resources associated with the user or process. 

The u-area is used by the operating system to track and manage resources associated with a particular user or process, and is an important part of the UNIX system architecture. It is typically stored in memory and is accessed by the operating system kernel when performing various tasks related to user and process management.

This is one of the most frequently asked UNIX interview questions for experienced professionals.

When 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 and stored in the table and then this Inode number serves as a medium to access Inode. Thus, an inode can be defined as an entry created and set aside on a section of the disk for a file system. It serves as a data structure and nearly stores information that is required to be known about a file. 

This information usually includes the following details; 

  • The File location on the disk 
  • The Size of the file 
  • The Device Id and Group Id 
  • The File mode information 
  • The File protection flags 
  • The Access privileges for owner, group. 
  • The Timestamps for file creation, modifications 

The Bourne shell (sh) is a command-line interpreter and programming language that is commonly used in the UNIX operating system. It was one of the first shells to be developed for UNIX, and it has served as the basis for many other shells that have been developed since. Some key features of the Bourne shell include: 

  • Command-line interface: The Bourne shell provides a command-line interface (CLI) for users to enter commands and execute programs. 
  • Scripting: The Bourne shell includes a programming language that can be used to write shell scripts, which are programs that automate tasks and processes. Shell scripts can be used to perform a wide range of tasks, such as automating system maintenance, managing system resources, and more. 
  • Variables: The Bourne shell supports the use of variables, which are named values that can be used to store data and pass it between commands and scripts. 
  • Control structures: The Bourne shell includes control structures such as loops and conditional statements, which can be used to control the flow of execution in a shell script. 
  • Input/output redirection: The Bourne shell supports the use of redirection operators, which allow users to redirect the input and output of commands and scripts to and from files, devices, and other sources. 
  • Job control: The Bourne shell supports the use of job control, which allows users to manage multiple processes and tasks concurrently. 
  • Customization: The Bourne shell can be customized through the use of environment variables and startup files, which allow users to set defaults and customize the behavior of the shell. 

Shell scripts often make it into the list of top UNIX interview questions. Expect to come across this popular question.

Command substitution is the method that is performed when 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 
  • Using the ''redirection'' and 'cat' commands, allows setting a variable to the content of the file. 
  • Allows setting a variable to the output of the loop. 

Here are some examples of command substitution using both methods: 

Using the (backtick) character: 

$ echo The current date is `date` 

This command will execute the "date" command and substitute its output (the current date) into the "echo" command, resulting in output that looks like "The current date is Mon Jan 17 14:09:39 EST "2022"" 

Using the $(command) syntax: 

$ echo The current date is $(date) 

This command will execute the "date" command and substitute its output (the current date) into the" "echo" command, resulting in output that looks like "The current date is Mon Jan 17 14:09:39 EST "2022"" 

Another example is to use the command substitution to list the number of files in a directory 

$ echo "There are $(ls -1 | wc -l) files in the current directory." 

This command will execute the "ls -1" command which lists all files in the directory one per line, and then pipes the output to" "wc "-l" command which counts the number of lines, and substitute the output in the "echo" command, resulting in output that looks "like "There are 10 files in the current directory." 

In the UNIX operating system, "piping" is a technique that allows the output of one command to be used as the input of another command. This is accomplished using the "pipe" operator, which is represented by the vertical bar character (|). 

Here's an example of how piping works: 

$ ls -l | grep ".txt" 

In this example, the "ls" command is used to list the files in the current directory, and the output of this command is passed to the "grep" command using the pipe operator. The "grep" command searches the output of the "ls" command for lines that contain the string ".txt" and displays them to the user. 

Piping is a powerful technique that allows users to chain together multiple commands and create complex command-line pipelines. It is often used in combination with other techniques such as input/output redirection and command substitution to create flexible and powerful command-line scripts and programs.

In the UNIX operating system, a "pid" (short for" "process "ID") is a unique numeric identifier that is assigned to every process that is created on the system. The pid is used to identify and track processes, and it is used by various system utilities and functions to operate on processes.

Each process on a UNIX system has a unique pid, which is automatically assigned by the operating system when the process is created. The pid of a process can be used to refer to the process in various contexts, such as when using the "kill" command to terminate a process or when using the" "ps" command to list processes on the system.

In addition to the pid, each process also has a "parent pid" (ppid), which is the pid of the process that created it. The ppid is used to track the process hierarchy on the system and can be used to identify the relationships between processes. 

A must-know for anyone looking for Shell scripting interview questions, you should make sure you are prepared for this.

In the UNIX operating system, the "alias" mechanism is a feature that allows users to create short, user-defined names for frequently used commands. Aliases can be used to simplify complex commands, or to create custom commands that perform multiple tasks in a single command line. 

To create an alias, you can use the "alias" command followed by the name of the alias and the command that it should execute. For example, to create an alias called" "ll" that executes the "ls -l" command, you could use the following command: 

alias ll='ls -l' 

Once the alias has been defined, you can use it just like any other command. For example, to list the files in the current directory in long format, you could use the following command:

||

Aliases are stored in the user's shell environment, and are available for use in any terminal window or shell session. They can be a useful tools for simplifying common tasks and streamlining workflows.

Description

Top UNIX Tips and Tricks for Programmers

Here are some tips and tricks that may be useful for programmers for the UNIX operating system: 

  1. Use the "man" command to access documentation for UNIX commands and utilities. For example, "man" will display the manual page for the "ls" command, which lists the files in a directory. 
  2. Use the "grep" command to search for text within files or the output of other commands. For example, "grep ERROR logfile.txt" will search for the string "ERROR" in the file "logfile.txt". 
  3. Use the "find" command to locate files based on their name, size, or other attributes. For example, "find . -name '*.txt' will find all files with a" ".txt" extension in the current directory and its subdirectories. 
  4. Use the "awk" command to process and manipulate text data. Awk is a powerful tool that can be used to extract, transform and print data from text files or the output of other commands. 
  5. Use the "sed" command to perform text manipulation tasks, such as search and replace insertion and deletion. Sed is a powerful command-line tool that can be used to manipulate text data in scripts and on the command line. 
  6. Use the "cut" command to extract specific fields or columns of data from text files or the output of other commands. 
  7. Use the "sort" command to sort the lines of a text file or the output of other commands. 
  8. Use the "uniq" command to remove duplicate lines from a text file or the output of other commands. 
  9. Use the "tee" command to redirect the output of a command to both the terminal and a file. This is useful for saving the output of a command to a file while also viewing it on the screen. 
  10. Use the "alias" command to create abbreviations for frequently used commands. This can save time and make it easier to use long or complex commands. 

How to Prepare for UNIX Interview Questions?

Here are some tips on UNIX basic commands for interview and how to prepare for the interview round: 

  • Review the fundamentals of UNIX: Familiarize yourself with the basic concepts and features of the UNIX operating system, including the file system, processes, users and permissions, and networking. 
  • Practice common UNIX commands: Get familiar with the syntax and options of common UNIX commands, such as "ls", "grep", "awk", "sed", "cut", "sort", and "uniq". You should also be familiar with common shell commands, such as "cd", "mkdir", and "rm". 
  • Review UNIX scripts and programming languages: If the job involves writing scripts or programs for UNIX, be prepared to demonstrate your knowledge of languages such as Bash, Perl, or Python. You should also be familiar with common UNIX tools and utilities, such as "make" and" "gcc". 
  • Understand system administration tasks: If the job involves administering UNIX systems, be prepared to discuss topics such as system installation, configuration, security, and maintenance. 
  • Review common interview questions: Some common interview questions for a UNIX job might include: 
    • What is the purpose of the "root" user in UNIX? 
    • How do you create a new user account in UNIX? 
    • How do you view the running processes in UNIX? 
    • How do you redirect the output of a command to a file in UNIX? 
    • How do you find the difference between two files in UNIX? 

Prepare to discuss your relevant experience: Be prepared to discuss any previous experience you have working with UNIX, including any projects you have worked on or challenges you have faced. You can start with the online Programming courses to know and read about UNIX Interview Questions. 

Job Roles

  • Systems administrator 
  • Network administrator 
  • Database administrator 
  • DevOps Engineer 
  • Security Engineer 
  • Cloud Engineer 
  • Software Developer 
  • Data Scientist/Analyst

Top Companies

  • Accenture 
  • IBM 
  • Infosys 
  • Capgemini 
  • Dell 
  • TCS 
  • HCL 
  • Randstad 
  • IQVIA 
  • Wipro 
  • Fujitsu 
  • CliqHR

What to Expect in a Shell Scripting Interview Questions?

In a UNIX interview, you can expect to be asked a variety of questions about your knowledge and experience working with the UNIX operating system. Some specific topics that you might be asked about include: 

  • Basic UNIX concepts and features, such as the file system, processes, users and permissions, and networking 
  • Common UNIX commands and shell scripts 
  • UNIX tools and utilities, such as "grep","awk", "sed"," and" "make" 
  • Programming languages commonly used on UNIX, such as Bash, Perl, and Python 
  • System administration tasks, such as installation, configuration, security, and maintenance 
  • Previous experience working with UNIX, including any projects you have worked on or challenges you have faced 

You can also expect to be asked UNIX commands interview questions about your problem-solving skills, communication abilities, and experience working in a team environment. It is important to be prepared to discuss these topics and to provide specific examples to illustrate your skills and experience. 

Summary

Preparing for UNIX shell scripting interview questions is important because it allows you to showcase your skills, experience, and qualifications in the best possible light. It also helps you to be more confident and relaxed during the interview, which can improve your chances of making a good impression on the hiring manager. Here are a few reasons why you should prepare for interview questions: 

  • It allows you to think about your strengths and weaknesses: Preparing for interview questions forces you to think about your skills, experience, and qualifications and how they relate to the job you are applying for. It also helps you to identify any gaps in your experience or areas where you need to improve.  
  • It helps you to articulate your qualifications: Preparing for interview questions gives you an opportunity to practice articulating your qualifications and explaining how your skills and experience match the requirements of the job. This can help you to communicate your value to the hiring manager more effectively. 
  • It helps you to stand out from other candidates: Preparing for interview questions can help you to anticipate the questions the interviewer may ask, and tailor your answers to demonstrate your qualifications and how you can be an asset to the company. 
  • It helps you to feel more confident: When you're well prepared, you will feel more confident and relaxed during the interview. This can help you to come across as more personable and engaged, which can improve your chances of making a good impression on the hiring manager. 
  • It helps you to be proactive about your professional development: Preparing for an interview is also a good opportunity to reflect on your goals and aspirations and think about how this position can help you to achieve them. 

Overall, preparing for UNIX interview questions is a great way to demonstrate your interest and commitment to the job and to increase your chances of getting the position. Hopefully, this article will help you prepare for your interview for the profile of Linux expert. These questions are not only for intermediate but also for highly experienced candidates appearing for the interview of Linux experts.

Read More
Levels