Shell scripting interview question part 2/Shell Scripting Interview Questions and Answers for Freshers & Experienced

What is it essential to write Shell Scripts?

Shell scripting has many benefits that make it crucial. It takes input from users, files it, and displays it on the screen. Moreover, it allows you to make your own commands and automate simple daily tasks. You can use Shell scripting to automate system administration tasks also. Shell scripting makes your processes more efficient by saving you a lot of energy and time. Due to this, it is quite essential and widely used.

Posted Date:- 2021-09-10 10:03:25

Can you differentiate between single quotes and double quotes?

Yes. We use single quotes where we don’t want to perform the variables’ evaluation to values. On the other hand, we use double quotes where we want to perform the variables’ evaluation to values.

Posted Date:- 2021-09-10 10:02:28

What are Vi Editor modes available?

While working with Vi Editor, different operations we perform are done in different modes.

1. Command Mode - Launching Vi automatically starts command mode.
2. Edit Mode - This mode provides an environment to edit text.
3. Ex Mode - Vi editor interaction is made available with file processing instructions.

Posted Date:- 2021-09-10 10:01:29

Difference between process and thread?

To put it in simple words, a thread is a small piece of code/instruction that needs to be executed in a process, whereas a process is a collection of one or more thread executions to complete one complete task.

Posted Date:- 2021-09-10 10:00:06

What are the types of permission at the file level in Shell?

Owner permissions: The permissions granted to a user with all the rights at the root level.

Group permissions: The permissions granted to a user with all the rights in a particular group.

Other permissions: The permissions granted to a user with all the rights globally to a file.

Posted Date:- 2021-09-10 09:59:26

Write a script to compare numbers?

If [ $x –gt $y ]
Echo “ x is greater than y”
Echo “y is greater than x”

Posted Date:- 2021-09-10 09:58:35

Write down the Syntax for all the loops in Shell Scripting.

For Loop:

for var in word1 word2 … wordn


Statement(s) to be executed for every word.


While Loop:

while command


Statement(s) to be executed if command is true


Until Loop:

until command


Statement(s) to be executed until command is true


Posted Date:- 2021-09-10 09:57:56

I want to create a directory such that anyone in the group can create a file and access any person’s file in it but none should be able to delete a file other than the one created by himself.

We can create the directory giving read and execute access to everyone in the group and setting its sticky bit “t” on as follows:

mkdir direc1

chmod g+wx direc1

chmod +t direc1

Posted Date:- 2021-09-10 09:57:15

Write a shell script to get current date, time, username and current working directory.

echo “Hello, $LOGNAME”
echo “Today’s date is `date`”
echo “Username is `who i am`”
echo “Current directory is `pwd`”

Posted Date:- 2021-09-10 09:56:09

How to connect to a remote server and execute some commands?

We can use ssh to do this:

ssh username@serverIP -p sshport

Once the above command is executed, enter the password.

Posted Date:- 2021-09-10 09:53:38

What are the different commands available to check the disk usage?

>> df: It is used to check the free disk space.
>> du: It is used to check the directory wise disk usage.
>> dfspace: It is used to check the free disk space in terms of MB.

Posted Date:- 2021-09-10 09:52:11

What are the two files of crontab command?

cron.allow which decides the users need to be permitted for using the crontab command.

cron.deny which decides the users need to be prevented from using the crontab command

Posted Date:- 2021-09-10 09:51:17

How many fields are present in a crontab file?

The five fields contain information on when to execute the command .

day of the week(0-6, Sunday = 0).

Posted Date:- 2021-09-10 09:50:36

What is the Crontab?

Crontab stands for cron table because it uses the job scheduler cron to execute tasks. The crontab is a list of commands that you want to run on a regular schedule, and also the name of the command used to manage that list.

Posted Date:- 2021-09-10 09:49:57

Which four fundamental components of every file system?

Boot block: it contains a small program called MBR which loads the kernel during system boot up.

Super block: super block contains all information about the file system.

Inode block: it contains inode for every file of the file system.

Posted Date:- 2021-09-10 09:49:17

How to find the status of the process?

Ps ux command user for find status of process.

Posted Date:- 2021-09-10 09:47:46

Explain “s” permission bit in a file?

“s” bit also called “set user id”(SUID) bit. “s” on file causes the process to have the privileges of the owner of the file during the instance of the program.

Posted Date:- 2021-09-10 09:47:01

What are “c” and “b” permission fields of a file?

“c ” and “b” permission fields are generally associated with a device file. It specifies whether a file is a special character file or a block special file.

Posted Date:- 2021-09-10 09:46:28

How do we create command aliases in a shell?

alias Aliasname=”Command whose alias is to be created”.

Posted Date:- 2021-09-10 09:45:58

What is an inode block?

This block contains the inode for every file of the file system along with all the file attributes except its name.

Posted Date:- 2021-09-10 09:44:56

What is a super block?

Super block contains all the information about the file system like the size of file system, block size used by its number of free data blocks and list of free inodes and data blocks.

Posted Date:- 2021-09-10 09:44:24

What are the four fundamental components of every file system on Linux?

Bootblock, super block, inode block and Datablock are found fundamental components of every file system on Linux.

Posted Date:- 2021-09-10 09:43:59

How do we delete all blank lines in a file?

sed '^ [(backslash)011(backslash)040]*$/d' file1
where (backslash)011 is an octal equivalent of space and

(backslash)040 is an octal equivalent of the tab

Posted Date:- 2021-09-10 09:43:25

What is the significance of $?

The command $? gives the exit status of the last command that was executed.

Posted Date:- 2021-09-10 09:42:59

How will you find the total disk space used by a specific user?

du -s /home/user1 ….where user1 is the user for whom the total disk space needs to be found.

Posted Date:- 2021-09-10 09:42:28

Write down the syntax of “for ” loop


for iterator in (elements)
execute commands

Posted Date:- 2021-09-10 09:41:59

How will you print the login names of all users on a system?

/etc/shadow file has all the users listed.

awk –F ':' '{print $1}' /etc/shadow|uniq -u

Posted Date:- 2021-09-10 09:41:31

What is the difference between grep and egrep?

egrep is Extended grep that supports added grep features like “+” (1 or more occurrence of a previous character),”?”(0 or 1 occurrence of a previous character) and “|” (alternate matching)

Posted Date:- 2021-09-10 09:40:08

How will you emulate wc –l using awk?

awk ‘END {print NR} fileName’

Posted Date:- 2021-09-10 09:39:37

What will happen to my current process when I execute a command using exec?

“exec” overlays the newly forked process on the current process; so when I execute the command using exec, the command gets executed on the current shell without creating any new processes.

Posted Date:- 2021-09-10 09:39:10

What are the 3 standard streams in Linux?

0 – Standard Input1 – Standard Output2 – Standard Error

Posted Date:- 2021-09-10 09:38:45

Define “Metacharacters.”

A Shell consists of metacharacters, which are special characters in a data field or program that offers information about other characters. For example, the “ls s*” command in a Shell lists all the files beginning with the character ‘s’.

Posted Date:- 2021-09-10 09:38:21

Define “IFS.”

IFS refers to Internal Field Separator. It is a system variable whose default value is space, tab, following by a new line. IFS denotes where a field or word ends in a line and where another begins.

Posted Date:- 2021-09-10 09:37:55

Name the Command used for Displaying the list of files in a directory.

$ ls -lrt | grep ^-? the command used for displaying the list of files in a directory.

Posted Date:- 2021-09-10 09:37:31

Which command is helpful to forward errors to a file?

The command that used for forwarding error to a file is 2> filename

Posted Date:- 2021-09-10 09:37:09

What is the difference between &/&&?

1. & - "Bitwise AND", evaluates both sides of the operation.

2. && - "Logical AND Operator", evaluates at the left side of the operation (If it is True) it continues at the right side.

Posted Date:- 2021-09-10 09:36:49

Define “Control Instructions.” How many types of control instructions are available in a Shell?

Control instructions are commands that allow you to specify how the different instructions in a script should be executed. Thus, their primary purpose is to determine the flow of control in a Shell program.

A Shell has four types of control instructions:

> Sequence control instruction enforces the instructions to be executed in the same order in which they are in the program.
> Selection/decision control instruction that enables the computer to determine which instruction should be executed next.
> Repetition/loop control instruction that allows the computer to run a group of statements repetitively.
Case-control instruction is used when you need to choose from a range of alternatives.

Posted Date:- 2021-09-10 09:35:56

Name the three modes of operation of vi editor.

The three modes of operation are:

> Command mode – This mode treats and interprets any key pressed by a user as editor commands.
> Insert mode – You can use this mode to insert a new text, edit an existing text, etc.
> Ex-command mode – A user can enter all commands at a command line.

Posted Date:- 2021-09-10 09:33:33

How many blocks does a file system contain?

A file system has four blocks:

1. Superblock – This block offers information on the state of a file system such as block size, block group size, usage information, empty/filled blocks and their respective counts, size & location of inode tables, etc.
2. Bootblock – This block holds the bootstrap loader program that executes when a user boots the host machine.
3. Datablock – This block includes the file contents of the file system.
Inode table – UNIX treats all elements as files, and all information related to files is stored in the inode table.

Posted Date:- 2021-09-10 09:32:41

How to create a shortcut in Linux?

You can create shortcuts in Linux via two links:

Hard link – These links are linked to the inode of the file. They are always present in the same file system as the file. Even if you delete the original file, the hard link will remain unaffected.

Soft link – These links are linked to the file name. They may or may not reside on the same file system as the file. If you delete the original file, the soft link becomes inactive.

Posted Date:- 2021-09-10 09:31:50

What are the advantages and disadvantages of shell scripting?

Advantages of shell scripting:

1. Can design applications (software) according to their platform.
2. To run a sequence of commands as a single command.
3. Portable (It can be executed in any Unix-like operating system without any modifications)

Disadvantages of shell scripting:

1. Slow execution speed compared to any programming languages
2. When a tying error occurs during the creation then it will delete the entire data as well as partition data.

Posted Date:- 2021-09-10 09:30:42

What command can be used to test if $a greater than 12?

The following command is used: [ $a -gt 12 ]

Posted Date:- 2021-09-10 09:29:36

Which is the Best Way To Pretty Print JSON On The Command-Line?

It can handle very large JSON structures, including streams.


$ jq . <<< '{ "foo": "lorem", "bar": "ipsum" }'
"bar": "ipsum",
"foo": "lorem"

Posted Date:- 2021-09-10 09:29:16

When should we use the “if” condition (before)?

When running several commands "if" condition meets.

Posted Date:- 2021-09-10 09:28:51

How you will make the soft link inactive in the scripting?

The soft links can simply be made inactive in your delete the file and the same doesn’t have any impact on the hard link and i.e. the users can access the file copy.

Posted Date:- 2021-09-10 09:28:28

Where exactly you can store the Shell programs in the system?

They are stored in a file which is tagged as Sh (Bourne Shell)

Posted Date:- 2021-09-10 09:28:07

Why writing the Shell Scripts is important according to you?

Well, this is important due to so many reasons and a few important ones are spotlighted below.

1. When it comes to creating customized commands or creating your own, shell scripting is very useful and powerful.
2. There are a lot of tasks that can easily be automated in the process.
3. The users are responsible for providing the input and this clearly means there will be no errors in the output.
4. It is good enough to be considered for time-saving.
5. A lot of system administration tasks can be accomplished and can be automated.

Posted Date:- 2021-09-10 09:27:47

How the break and continue in the system are different from one another in scripting?

When a: Break” is used within a shell scripting loop is considered, it simply terminates the entire loop. On the other side, the “Continue” will make only the current iteration terminate.

However, you can have the loop available with you in the next iteration. These are the two powerful and in fact very useful features when it comes to constructing the shell.

Posted Date:- 2021-09-10 09:26:55

Are you familiar with the methods that are useful in debugging a problem related to the shell script?

The answer to this question depends on the skills of a professional. There are various methods and it is not always necessary that all users consider a similar method for problem debugging. Also, it actually depends on the problem itself.

The first method that can help users to formulate the problem is simply inserting some debug statements. This will actually help the pinpoint to know how and where the problem was declared itself or reported. Another method that is also common and the users can make use of it is set-x.

Posted Date:- 2021-09-10 09:26:31

Tell the procedure of accessing the command line arguments from a script?

It can be done simply by executing the $ in the system. It will show all the arguments that have already passed from the command line to a script.

Sometimes you need to specify the argument’s numeric position and the users have to make sure that things are done in a rightful manner.

Posted Date:- 2021-09-10 09:25:36

Is it possible to use a shell script to determine if the directory actually exists or not?

Yes, this is possible and for this, the users are free to simply consider the UNIX test command. The option that is useful is the –d option. It is not always necessary that the information regarding the existence of a directory is displayed only when the directory is recognized by the system.

Information regarding all the directories whether known to the system or not can be displayed with this command. Generally, directories are present in the variable $mydir.

Posted Date:- 2021-09-10 09:24:04

What is the difference between = and ==?

= This is used for assigning value to the variable.
== This is used for string comparison.

Posted Date:- 2021-09-10 09:23:07

How to debug the problems encountered in the shell script/program?

Given below are some common methods used to debug the problems in the script.

Debug statements can be inserted in the shell script to output/display the information which helps to identify the problem.
Using set -x we can enable debugging in the script.

Posted Date:- 2021-09-10 09:21:38

Do you need a separate compiler to execute a Shell program?

No, you don’t need a separate compiler to execute a Shell program. Since Shell itself is a command-line in the shell program and executes them.

Posted Date:- 2021-09-10 09:20:48

How will you pass and access arguments to a script in Linux?

For pass arguments in script “scriptname arg1 arg2 arg3 …”

For access arguments in script can be accessed inside the script as “$1 , $2 .. $n”

Posted Date:- 2021-09-10 09:18:57

R4R Team
R4R provides Shell Scripting Freshers questions and answers (Shell Scripting Interview Questions and Answers) .The questions on website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,Shell scripting interview question part 2,Shell Scripting Freshers & Experienced Interview Questions and Answers,Shell Scripting Objetive choice questions and answers,Shell Scripting Multiple choice questions and answers,Shell Scripting objective, Shell Scripting questions , Shell Scripting answers,Shell Scripting MCQs questions and answers R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for Shell Scripting fresher interview questions ,Shell Scripting Experienced interview questions,Shell Scripting fresher interview questions and answers ,Shell Scripting Experienced interview questions and answers,tricky Shell Scripting queries for interview pdf,complex Shell Scripting for practice with answers,Shell Scripting for practice with answers You can search job and get offer latters by studing .learn in easy ways .