Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What is the best way to run a script in the background?

Answer»

For a SCRIPT to run in the BACKGROUND, SIMPLY ADD "&" at the end of the command.

Example:

script.sh &

command &

2.

What is the use of the "$?" command?

Answer»

By USING the COMMAND "$?", you can FIND out the status of the LAST command executed.

3.

What does the . (dot) indicate at the beginning of the file name? How can it be listed?

Answer»

If the file name begins with ".", it is a hidden file. When a dot appears at the beginning of a filename, the file is hidden in most file managers and shell PROGRAMS. A Shell usually lists all the files except hidden files when you try to list the files in a shell. Despite this, hidden files can be found in the DIRECTORY. The Is COMMAND must be run with the "–a" FLAG if you wish to SEE hidden files.

4.

How long does a variable in a shell script last?

Answer»

VARIABLES inside shell scripts have a LIFESPAN of only as long as the EXECUTION LASTS.

5.

Name the command that can be used to find out the number of arguments passed to the script?

Answer»

The following COMMAND will display the number of ARGUMENTS PASSED to the script: ECHO $ #

6.

Write the command that is used to execute a shell file.

Answer»

Firstly, USE the chmod command to SET execute PERMISSION on your SCRIPT as shown below: 

chmod +x script-name-here.SH 

Secondly, run or execute your script as follows: 

./script-name-here.sh 

Alternatively, you can execute shell script by: 

sh script-name-here.sh

7.

What is the importance of $#?

Answer»

$# usually holds the number of arguments, although it may be DIFFERENT for FUNCTIONS. To put it SIMPLY, it was USED to STORE the number of command-line arguments passed to a shell script.

8.

Explain the way you can connect to a database server.

Answer»

Open client DRIVER COMES with the isql utility that can be used to connect to a database SERVER from Linux. Here's how to do it: 

isql –S SERVERNAME –U username –P password 

9.

Name the alternative command for echo.

Answer»

The tput COMMAND is an alternative command for echo. We can USE this command to control how the output is DISPLAYED.  Additionally, shell SCRIPTS can do things such as underline text and center text, regardless of the size of the SCREEN.

10.

What is a file system? Write down the four core components of a Linux file system.

Answer»

Generally, file systems are referred to as the collections of files, which include information related to those files. It would be impossible to tell where one piece of data stops and the next begins without a file system. There are four blocks in a file system: 

  • Super Block: A superblock CONTAINS information about a file system, including block size, group size, USAGE statistics, empty/filled blocks, inode table size & location, and so on. One of the tools used to describe a file system, along with inodes, entries, and files, is the superblock. Multiple superblocks are CREATED with the file system, as the superblock contains critical information.  
  • Boot Block: Located on the disk label, a boot block is a special set of blocks that contains data or information on the disk layout. Normally, this block contains the bootstrap loader program, which a user runs upon LAUNCHING the host computer. The boot block remains blank if the file system is not used for boot.    
  • Data Block: Also called storage blocks, data blocks contain the remainder of the space allocated to the file system. The data block's size is measured at the time of file system creation. For a regular file, the CONTENT of files is contained in the data blocks. For directories, the inode number and file name of the files are contained in the data blocks.  
  • Inode: Inodes contain information about each file in the filesystem. Normally, an inode doesn't contain a file's name, which is located in a directory instead.  An inode contains information such as the type of file, the permission bits, the owner, the group, the file size, and the time when the file was modified.
11.

What is the shebang line in shell scripting?

Answer»

Shell scripts or programs often contain shebang at the top. In general, the Shebang (the SERIES of characters "#!") is used to indicate the operating system to use a particular interpreter to process the rest of the file. Here, the SYMBOL '#' is referred to as HASH, and "!" is referred to as bang. This usually aids developers in avoiding repetitive work. Scripts are generally executed by the engine; therefore, shebang DETERMINES the location of the engine that will be used to run the script. 

Example:  

#!/bin/bash  

In addition, this line also SPECIFIES which shell to use.

12.

What do you mean by GUI Scripting?

Answer»

The GUI (GRAPHICAL User Interface) is a client/server interface that uses graphical ICONS and VISUAL indicators to allow USERS to interact with devices. Specifically, it is used to control a COMPUTER and its applications. A wide variety of applications are supported, and it is largely dependent on the operating system.

13.

Write difference between Hard link and Soft Link.

Answer»
Hard LinkSoft Link
Hard-linked files have the same INODE number. Soft-linked files have different inode numbers.
Despite deleting the target file, it REMAINS valid.When an original file is deleted, it BECOMES invalid.
Hard links are faster than soft links. Soft links are SLOWER than hard links.
The command used for creating a hard link in Linux is "ln".  The command used for creating a soft link in Linux is “ln -s”.
There is no way to use it ACROSS file systems.  You can use it on any file system.
Hard links cannot use relative paths. Both absolute and relative paths can be used in soft links. 
14.

How to check whether a link is a hard one or a soft link?

Answer»

We can use -H and -L OPERATORS of the test command to check WHETHER a link is HARD or SOFT (symbolic link).

  • -h file      //true if the file is a symbolic link
  • -L file      //true if the file is a symbolic link

One can also use:

readlink FILE; echo $?       // This returns 1 if it's a hard link and 0 if it's a symbolic link.

15.

Explain ways to create shortcuts in Linux.

Answer»

Links PRESENT in LINUX OS can be used to create shortcuts as given below: 

  • Hard Link: Hard links are mirror images of the originally linked files and are linked with an INODE number. A hard-linked file remains even after the original file is deleted. SINCE hard links point to inodes, they cannot be implemented on directories. Hard links are created by the following command:
$ ln  [original filename] [link name]
  • Soft Link: Generally, soft links (also referred to as Symbolic links) are linked to the file name and can reside on the same as well as different file systems. When a soft link is created or deleted, it does not affect the original file, but when the original file is deleted, the soft link stops working. Typically, soft links are aliases (ALTERNATIVE paths) for the original file. Soft links are created by the following command:
$ ln  -s [original filename] [link name]
16.

How many types of control instructions are available in a shell?

Answer»

Shells provide four types of control instructions as given below:  

  • Sequence Control Instruction: This ASSURES that a program's command RUNS in the sequence they are listed. As SOON as the first command in the sequence has been completed, the second command follows, and so on.
  • Decision Control Instruction: It is also known as Selection Control Instruction. This instructs the computer which instruction it should execute next. In this, checking a condition is the basis for deciding which section to execute. If a given condition is True, a statement or set of STATEMENTS will be executed; otherwise, they will be ignored.
  • Loop Control Instruction: It is also known as Repetition Instruction. This instruction allows a computer to continuously run a particular sequence of code. In a loop structure, the statements can be repeated until a condition is True or False, a particular number of times, or once for each element within the collection
  • Case-Control Instruction: This is used for selecting among several CHOICES. Typically, they are used to execute only a particular block of statements within a series of statements.
17.

What are control instructions?

Answer»

Control instructions specify how the different instructions will be EXECUTED in the script. They are primarily used to DETERMINE the control flow in Shell programs. The execution of a shell script proceeds in succession WITHOUT these instructions. In shell programs, control instructions govern how execution flows.

18.

Explain the term positional parameters.

Answer»

In a shell program, positional parameters specify arguments that are used to launch the current process. A special set of variables is usually maintained by the shell for storing positional parameter values. BASH is an EXAMPLE of a shell that uses positional parameters. The bash shell can be used on Linux, BSD, macOS X, and Windows 10.

For example: 

mycommand ONE five "SIX four”   

In this case, the command name is mycommand, and there are four parameters in the command line: one, five, and "six four”.   

Note: A space delimits each positional parameter and each thing after spaces are interpreted by the shell as individual parameters. Therefore, the parameter itself should be enclosed in quotation marks if it CONTAINS a space, as in "six four".

19.

What are different types of variables mostly used in shell scripting?

Answer»

Shell scripts usually have two types of variables:  

  • System-defined variables: ALSO CALLED environment variables, these are special built-in variables in the Linux kernel for each shell. They are normally defined in capital letters by the OS (Linux) and are standard variables.
    Example:  
    SHELL  
    It is a Unix Defined or System Variable, which specifies the default working shell. 
  • User-defined variables: These variables are created and defined by users in order to store, access, read, and manipulate DATA. In general, they are defined in lowercase letters. The Echo command allows you to view them.
    Example:    
    $ a=10 
    In this CASE, the user has defined the variable ‘a’ and assigned it the value 10.
20.

What do you mean by Shell variable?

Answer»

Shell variables are integral parts of all Shell PROGRAMS and SCRIPTS. In general, we know that variables usually store data either in the form of characters or NUMBERS. Shell also STORES and manipulates information using variables in its programs. Generally, shell variables are stored as strings. Variables in the shell provide the information needed for scripts/commands to execute. In the following EXAMPLE, a shell variable is created and then printed: 

variable ="Hello" 
echo $variable 

21.

Write difference between Bourne Shell and C Shell.

Answer»
  • Bourne Shell: It has compactness and speed that SET it apart from other shells. But it lacks interactive features such as the ability to recall previous commands. Additionally, the Bourne shell does not support ARITHMETIC and logical expressions.
  • C Shell: It is a UNIX enhancement that incorporates interactive features like ALIASES and history of commands. Besides its built-in arithmetic and expression syntax, it also includes CONVENIENT programming features.

Difference between Bourne shell and C shell   

  • The C shell allows you to alias commands easily, whereas Bourne Shell does not allow this.
  • In the C shell, long commands can be used repeatedly, but not in Bourne.
  • Bourne does not have access to the command history, but the C shell does.
  • In the CASE of C, there is no need to repeatedly type the command.
22.

Name different types of shells available.

Answer»
  • Shells are divided into two categories: 
    • Bourne shell: The $ character is the default prompt when using a Bourne-type shell.
    • C shell: The % character is the default prompt when using a C-type shell.

The Bourne-type is subdivided into the FOLLOWING categories:

  • Bourne Again shell (BASH): This is the most common shell available on all Linux and based systems. It is open-source and freeware. In addition, it is an SH-compatible shell, with improved programming and interactive features over SH. It also allows you to EFFICIENTLY perform many tasks.
  • Korn shell (KSH): Korn is basically a Unix shell that was initially based on the Bash Shell Scripting. It's a high-level language that's quite advanced. It has associative arrays and handles the loop syntax better than Bash. It is basically an improved version of Bourne shell.

The C-type is subdivided into the following categories:   

  • C shell (CSH): C shell is almost like C itself since it uses the shell syntax of the C programming language. In most cases, a command is EXECUTED either interactively from a terminal keyboard or from a file.
  • TENEX/TOPS C shell (TCSH): TCSH does not have a specific full name. TCSH is considered as an enhanced version of the CSH as it includes some additional features over CSH like command-line editing and filename or command completion. As with the PREVIOUS version, it supports C-style syntax also.
23.

Name the file in which shell programs are stored.

Answer»

A file CALLED sh stores shell PROGRAMS. Sh FILES contain commands written in a SCRIPTING language that is run by Unix SHELLS.

24.

Write some limitations of shell scripting.

Answer»

Shell scripting has the following disadvantages:

  • Errors are frequent and costly, and a single error can alter the command.  
  • The EXECUTION speed is SLOW
  • Bugs or inadequacies in the language's syntax or implementation.  
  • Large, complex tasks aren't well suited to it.  
  • CONTRARY to other scripting languages, ETC., it provides a minimal data structure.   
  • Every TIME a shell command is executed, a new process is launched.
25.

Write some advantages of shell scripting.

Answer»

Shell scripting offers the following benefits:

  • An interactive debugging tool, as well as a quick start.   
  • Programmers need not change their syntax since both command and syntax are identical to those entered directly into the command line.  
  • Shell scripts are EASY to USE and quicker to write.   
  • It helps automate administrative tasks, so it is time-saving.   
  • As shell scripts are written in an interpreted language, they can be run without any additional effort on almost any modern operating SYSTEM, including UNIX, Linux, BSD, and Mac OS X.  
  • They can be utilized for BULK execution rather than single instructions.   
  • Using it, you can develop your own custom operating system with relevant features.  
  • Software applications can be developed according to their respective platforms with this tool.
26.

Why is a shell script needed?

Answer»

Shell SCRIPTS can be WRITTEN for a variety of reasons:

  • Keeping REPETITIVE tasks to a minimum.
  • Can be used by system administrators for routine backups.
  • Monitoring the system.
  • Adding new FUNCTIONS to the shell.
  • Shell scripting ALLOWS you to create your own tools.
  • System admin can automate daily tasks.
27.

What is Shell?

Answer»

A Shell is basically a command-line interpreter between user and kernel or a complete ENVIRONMENT specially designed to run COMMANDS, shell scripts, and programs. In this, whenever a user enters human-readable commands (input commands) through the keyboard, the shell communicates with the kernel to execute these commands, and DISPLAY output in a shell script. Just as there are different flavors of operating systems, there are also different types of shells. Every shell has its own set of commands and functions. Shells ISSUE the prompt, $, called a command prompt. You can type into the prompt while it is displayed.  

After you press enter, your input is read by the shell. Based on the first word of your input, it determines the command you want to run. The characters in a word are separated using spaces and tabs.  

Example: 

Here is an example of a date command that displays the current date and time:  

$date Tue Aug 10 06:03:35 MST 2021